-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Quick Open enhancements & API cleanup #1565
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,8 +75,7 @@ define(function (require, exports, module) { | |
var docText = doc.getText(); | ||
var lines = docText.split("\n"); | ||
|
||
|
||
var regex = new RegExp(/\s*id\s*?=\s*?["'](.*?)["']/gi); | ||
var regex = new RegExp(/\s+id\s*?=\s*?["'](.*?)["']/gi); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Nit: there are multiple empty lines before this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
var id, chFrom, chTo, i, line; | ||
for (i = 0; i < lines.length; i++) { | ||
line = lines[i]; | ||
|
@@ -113,17 +112,19 @@ define(function (require, exports, module) { | |
|
||
/** | ||
* @param {string} query what the user is searching for | ||
* @returns {Array.<string>} sorted and filtered results that match the query | ||
* @returns {Array.<SearchResult>} sorted and filtered results that match the query | ||
*/ | ||
function search(query) { | ||
createIDList(); | ||
|
||
query = query.slice(query.indexOf("@") + 1, query.length); | ||
|
||
// Filter and rank how good each match is | ||
var filteredList = $.map(idList, function (itemInfo) { | ||
if (itemInfo.id.toLowerCase().indexOf(query.toLowerCase()) !== -1) { | ||
return itemInfo.id; | ||
} | ||
}).sort(); | ||
return QuickOpen.stringMatch(itemInfo.id, query); | ||
}); | ||
|
||
// Sort based on ranking & basic alphabetical order | ||
QuickOpen.basicMatchSort(filteredList); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ignores case when sorting, and id's are case sensitive. |
||
|
||
return filteredList; | ||
} | ||
|
@@ -144,20 +145,20 @@ define(function (require, exports, module) { | |
|
||
/** | ||
* Select the selected item in the current document | ||
* @param {HTMLLIElement} selectedItem | ||
* @param {?SearchResult} selectedItem | ||
*/ | ||
function itemFocus(selectedItem) { | ||
var fileLocation = getLocationFromID($(selectedItem).text()); | ||
if (!selectedItem) { | ||
return; | ||
} | ||
var fileLocation = getLocationFromID(selectedItem.label); | ||
if (fileLocation) { | ||
var from = {line: fileLocation.line, ch: fileLocation.chFrom}; | ||
var to = {line: fileLocation.line, ch: fileLocation.chTo}; | ||
EditorManager.getCurrentFullEditor().setSelection(from, to); | ||
} | ||
} | ||
|
||
/** | ||
* TODO: selectedItem is currently a <LI> item from smart auto complete container. It should just be data | ||
*/ | ||
function itemSelect(selectedItem) { | ||
itemFocus(selectedItem); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,29 +110,19 @@ define(function (require, exports, module) { | |
|
||
/** | ||
* @param {string} query what the user is searching for | ||
* @returns {Array.<string>} sorted and filtered results that match the query | ||
* @returns {Array.<SearchResult>} sorted and filtered results that match the query | ||
*/ | ||
function search(query) { | ||
createFunctionList(); | ||
|
||
query = query.slice(query.indexOf("@") + 1, query.length); | ||
|
||
// Filter and rank how good each match is | ||
var filteredList = $.map(functionList, function (itemInfo) { | ||
|
||
var functionName = itemInfo.functionName; | ||
if (functionName.toLowerCase().indexOf(query.toLowerCase()) !== -1) { | ||
return functionName; | ||
} | ||
}).sort(function (a, b) { | ||
a = a.toLowerCase(); | ||
b = b.toLowerCase(); | ||
if (a > b) { | ||
return -1; | ||
} else if (a < b) { | ||
return 1; | ||
} else { | ||
return 0; | ||
} | ||
return QuickOpen.stringMatch(itemInfo.functionName, query); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JavaScript function names are case sensitive. Bonus: case sensitive string matching is faster! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought, since this is "quick" open it should probably ignore case when searching, but respect case when sorting. For example, in the case where there's multiple matches that are all lower-case and also multiple matches that are mixed-case, I think that it would make it easier to differentiate between the choices if they were separated and not mixed together. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re the various comments on case-sensitivity... The existing behavior of Quick Open is to do everything case-insensitively, and since it's been around a while I'd rather wait and not muck with it in this patch. Although my personal feeling is that we should stay case-insensitive even in the long run (seems more consistent with other tools & other Brackets features), it seems reasonable to raise this with the broader team. We could always change it down the road if I'm in the minority. Does that sound ok to you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK by me. |
||
}); | ||
|
||
// Sort based on ranking & basic alphabetical order | ||
QuickOpen.basicMatchSort(filteredList); | ||
|
||
return filteredList; | ||
} | ||
|
@@ -153,10 +143,13 @@ define(function (require, exports, module) { | |
|
||
/** | ||
* Select the selected item in the current document | ||
* @param {HTMLLIElement} selectedItem | ||
* @param {?SearchResult} selectedItem | ||
*/ | ||
function itemFocus(selectedItem) { | ||
var fileLocation = getLocationFromFunctionName($(selectedItem).text()); | ||
if (!selectedItem) { | ||
return; | ||
} | ||
var fileLocation = getLocationFromFunctionName(selectedItem.label); | ||
|
||
if (fileLocation) { | ||
var from = {line: fileLocation.line, ch: fileLocation.chFrom}; | ||
|
@@ -165,9 +158,6 @@ define(function (require, exports, module) { | |
} | ||
} | ||
|
||
/** | ||
* TODO: selectedItem is currently a <LI> item from smart auto complete container. It should just be data | ||
*/ | ||
function itemSelect(selectedItem) { | ||
itemFocus(selectedItem); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's worth handling, but CSS Selectors have a mix of case sensitivity (id's and classes) and insensitivity (everything else), and this method ignores case.