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

Commit

Permalink
Merge pull request #1790 from JakeStoeffler/issue-1604
Browse files Browse the repository at this point in the history
Make URLs breakable in certain cases
  • Loading branch information
redmunds committed Oct 7, 2012
2 parents a856faa + 55c8c9f commit 82ef833
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
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;
});

0 comments on commit 82ef833

Please sign in to comment.