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

Commit 55c8c9f

Browse files
committed
Make URLs breakable
See issue #1604
1 parent a856faa commit 55c8c9f

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/search/FindInFiles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ define(function (require, exports, module) {
215215

216216
// Add row for file name
217217
$("<tr class='file-section' />")
218-
.append("<td colspan='3'>" + StringUtils.format(Strings.FIND_IN_FILES_FILE_PATH, item.fullPath) + "</td>")
218+
.append("<td colspan='3'>" + StringUtils.format(Strings.FIND_IN_FILES_FILE_PATH, StringUtils.breakableUrl(item.fullPath)) + "</td>")
219219
.click(function () {
220220
// Clicking file section header collapses/expands result rows for that file
221221
var $fileHeader = $(this);

src/search/QuickOpen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ define(function (require, exports, module) {
569569
// Use the filename formatter
570570
query = StringUtils.htmlEscape(query);
571571
var displayName = StringUtils.htmlEscape(item.label);
572-
var displayPath = StringUtils.htmlEscape(ProjectManager.makeProjectRelativeIfPossible(item.fullPath));
572+
var displayPath = StringUtils.breakableUrl(StringUtils.htmlEscape(ProjectManager.makeProjectRelativeIfPossible(item.fullPath)));
573573

574574
if (query.length > 0) {
575575
// make the user's query bold within the item's text

src/utils/StringUtils.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ define(function (require, exports, module) {
140140
return (a2 > b2) ? 1 : -1;
141141
}
142142
}
143+
144+
/**
145+
* Return a path or URL string that can be broken near path separators.
146+
* @param {string} url the path or URL to format
147+
* @return {string} the formatted path or URL
148+
*/
149+
function breakableUrl(url) {
150+
// Inject zero-width space character (U+200B) near path separators (/) to allow line breaking there
151+
return url.replace(
152+
new RegExp(regexEscape("/"), "g"),
153+
"/" + "&#8203;"
154+
);
155+
}
143156

144157
// Define public API
145158
exports.format = format;
@@ -149,4 +162,5 @@ define(function (require, exports, module) {
149162
exports.getLines = getLines;
150163
exports.offsetToLineNum = offsetToLineNum;
151164
exports.urlSort = urlSort;
165+
exports.breakableUrl = breakableUrl;
152166
});

0 commit comments

Comments
 (0)