From 55c8c9fda3263b8c976ccc4088cdcd6078063b32 Mon Sep 17 00:00:00 2001 From: Jake Stoeffler Date: Sat, 6 Oct 2012 22:38:14 -0500 Subject: [PATCH] Make URLs breakable See issue #1604 --- src/search/FindInFiles.js | 2 +- src/search/QuickOpen.js | 2 +- src/utils/StringUtils.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/search/FindInFiles.js b/src/search/FindInFiles.js index 6149350a9ef..12737095029 100644 --- a/src/search/FindInFiles.js +++ b/src/search/FindInFiles.js @@ -215,7 +215,7 @@ define(function (require, exports, module) { // Add row for file name $("") - .append("" + StringUtils.format(Strings.FIND_IN_FILES_FILE_PATH, item.fullPath) + "") + .append("" + StringUtils.format(Strings.FIND_IN_FILES_FILE_PATH, StringUtils.breakableUrl(item.fullPath)) + "") .click(function () { // Clicking file section header collapses/expands result rows for that file var $fileHeader = $(this); diff --git a/src/search/QuickOpen.js b/src/search/QuickOpen.js index ea600f3009c..4e3be11082d 100644 --- a/src/search/QuickOpen.js +++ b/src/search/QuickOpen.js @@ -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 diff --git a/src/utils/StringUtils.js b/src/utils/StringUtils.js index a89b604f6a4..9d29882a5bd 100644 --- a/src/utils/StringUtils.js +++ b/src/utils/StringUtils.js @@ -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"), + "/" + "​" + ); + } // Define public API exports.format = format; @@ -149,4 +162,5 @@ define(function (require, exports, module) { exports.getLines = getLines; exports.offsetToLineNum = offsetToLineNum; exports.urlSort = urlSort; + exports.breakableUrl = breakableUrl; });