Permalink
Browse files

Fixing escaping so that code that bolds query within item works corre…

…ctly. Fixed up a few remaining references to "QuickFileOpen" and changed to QuickOpen
  • Loading branch information...
1 parent f3f3a97 commit 1f63ea723e3823dce7ec8f9f6b66309bb6a3af80 @tvoliter tvoliter committed May 4, 2012
Showing with 33 additions and 11 deletions.
  1. +1 −1 src/brackets.js
  2. +1 −1 src/extensions/default/README.txt
  3. +1 −1 src/search/FindInFiles.js
  4. +30 −8 src/search/QuickOpen.js
View
@@ -63,7 +63,7 @@ define(function (require, exports, module) {
CodeHintManager = require("editor/CodeHintManager"),
PerfUtils = require("utils/PerfUtils"),
FileIndexManager = require("project/FileIndexManager"),
- QuickFileOpen = require("search/QuickOpen"),
+ QuickOpen = require("search/QuickOpen"),
Menus = require("command/Menus"),
FileUtils = require("file/FileUtils"),
Strings = require("strings"),
@@ -1,4 +1,4 @@
This directory contains extensions that ship with brackets and are enabled
-by default. Examples may include things like QuickFileOpen.
+by default. Examples include extensions for QuickOpen.
(README also serves as a dummy file so this directory can be added to git.)
@@ -50,7 +50,7 @@ define(function (require, exports, module) {
EditorManager = require("editor/EditorManager"),
FileIndexManager = require("project/FileIndexManager");
- // This dialog class was mostly copied from QuickFileOpen. We should have a common dialog
+ // This dialog class was mostly copied from QuickOpen. We should have a common dialog
// class that everyone can use.
/**
View
@@ -420,25 +420,47 @@ define(function (require, exports, module) {
}
function defaultResultsFormatter(item, query) {
- query = StringUtils.htmlEscape(query.slice(query.indexOf("@") + 1, query.length));
- var boldName = item.replace(new RegExp(query, "gi"), "<strong>$&</strong>");
- return "<li>" + boldName + "</li>";
+ query = query.slice(query.indexOf("@") + 1, query.length);
+
+ // Escape both query and item so the replace works properly below
+ query = StringUtils.htmlEscape(query);
+ item = StringUtils.htmlEscape(item);
+
+ var displayName;
+ if(query.length > 0 ) {
+ // make the users query bold within the item's text
+ displayName = item.replace(new RegExp(query, "gi"), "<strong>$&</strong>");
+ } else {
+ displayName = item;
+ }
+
+ return "<li>" + displayName + "</li>";
}
function _handleResultsFormatter(item) {
- var query = StringUtils.htmlEscape(($('input#quickOpenSearch').val()));
+ var query = $('input#quickOpenSearch').val();
if (currentPlugin) {
+ // Plugins use their own formatter or the default formatter
var formatter = currentPlugin.resultsFormatter || defaultResultsFormatter;
return formatter(item, query);
} else {
- // Format filename result
- var filename = _filenameFromPath(item, true);
+ // Use the filename formatter
+ query = StringUtils.htmlEscape(query);
+ var filename = StringUtils.htmlEscape(_filenameFromPath(item, true));
var rPath = StringUtils.htmlEscape(ProjectManager.makeProjectRelativeIfPossible(item));
- var boldName = filename.replace(new RegExp(query, "gi"), "<strong>$&</strong>");
- return "<li data-fullpath='" + encodeURIComponent(item) + "'>" + boldName +
+
+ var displayName;
+ if(query.length > 0 ) {
+ // make the users query bold within the item's text
+ displayName = filename.replace(new RegExp(query, "gi"), "<strong>$&</strong>");
+ } else {
+ displayName = filename;
+ }
+
+ return "<li data-fullpath='" + encodeURIComponent(item) + "'>" + displayName +
"<br><span class='quickOpenPath'>" + rPath + "</span></li>";
}
}

0 comments on commit 1f63ea7

Please sign in to comment.