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 #1565 from adobe/pflynn/quick-open-sort
Browse files Browse the repository at this point in the history
Quick Open enhancements & API cleanup
  • Loading branch information
redmunds committed Sep 10, 2012
2 parents 5c01d31 + 3b3a37c commit 0e2ea3b
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 148 deletions.
35 changes: 12 additions & 23 deletions src/extensions/default/QuickOpenCSS/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,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) {
createSelectorList();

query = query.slice(query.indexOf("@") + 1, query.length);

// Filter and rank how good each match is
var filteredList = $.map(selectorList, function (itemInfo) {

var selector = itemInfo.selector;

if (selector.toLowerCase().indexOf(query.toLowerCase()) !== -1) {
return selector;
}
}).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.selector, query);
});

// Sort based on ranking & basic alphabetical order
QuickOpen.basicMatchSort(filteredList);

return filteredList;
}
Expand All @@ -124,20 +113,20 @@ define(function (require, exports, module) {

/**
* Select the selected item in the current document
* @param {HTMLLIElement} selectedItem
* @param {?SearchResult} selectedItem
*/
function itemFocus(selectedItem) {
var selectorInfo = getLocationFromSelectorName($(selectedItem).text());
if (!selectedItem) {
return;
}
var selectorInfo = getLocationFromSelectorName(selectedItem.label);
if (selectorInfo) {
var from = {line: selectorInfo.selectorStartLine, ch: selectorInfo.selectorStartChar};
var to = {line: selectorInfo.selectorStartLine, ch: selectorInfo.selectorEndChar};
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);
}
Expand Down
27 changes: 14 additions & 13 deletions src/extensions/default/QuickOpenHTML/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
var id, chFrom, chTo, i, line;
for (i = 0; i < lines.length; i++) {
line = lines[i];
Expand Down Expand Up @@ -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);

return filteredList;
}
Expand All @@ -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);
}
Expand Down
34 changes: 12 additions & 22 deletions src/extensions/default/QuickOpenJavaScript/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

// Sort based on ranking & basic alphabetical order
QuickOpen.basicMatchSort(filteredList);

return filteredList;
}
Expand All @@ -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};
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit 0e2ea3b

Please sign in to comment.