Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Make URLs breakable in certain cases #1790

Merged
merged 1 commit into from
Oct 7, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/search/FindInFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ define(function (require, exports, module) {

// Add row for file name
$("<tr class='file-section' />")
.append("<td colspan='3'>" + StringUtils.format(Strings.FIND_IN_FILES_FILE_PATH, item.fullPath) + "</td>")
.append("<td colspan='3'>" + StringUtils.format(Strings.FIND_IN_FILES_FILE_PATH, StringUtils.breakableUrl(item.fullPath)) + "</td>")
.click(function () {
// Clicking file section header collapses/expands result rows for that file
var $fileHeader = $(this);
Expand Down
2 changes: 1 addition & 1 deletion src/search/QuickOpen.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ define(function (require, exports, module) {
// Use the filename formatter
query = StringUtils.htmlEscape(query);
var displayName = StringUtils.htmlEscape(item.label);
var displayPath = StringUtils.htmlEscape(ProjectManager.makeProjectRelativeIfPossible(item.fullPath));
var displayPath = StringUtils.breakableUrl(StringUtils.htmlEscape(ProjectManager.makeProjectRelativeIfPossible(item.fullPath)));

if (query.length > 0) {
// make the user's query bold within the item's text
Expand Down
14 changes: 14 additions & 0 deletions src/utils/StringUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ define(function (require, exports, module) {
return (a2 > b2) ? 1 : -1;
}
}

/**
* Return a path or URL string that can be broken near path separators.
* @param {string} url the path or URL to format
* @return {string} the formatted path or URL
*/
function breakableUrl(url) {
// Inject zero-width space character (U+200B) near path separators (/) to allow line breaking there
return url.replace(
new RegExp(regexEscape("/"), "g"),
"/" + "&#8203;"
);
}

// Define public API
exports.format = format;
Expand All @@ -149,4 +162,5 @@ define(function (require, exports, module) {
exports.getLines = getLines;
exports.offsetToLineNum = offsetToLineNum;
exports.urlSort = urlSort;
exports.breakableUrl = breakableUrl;
});