From 2f0f4ae7217c6710f600abf854b1501c9c783b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Tue, 4 Mar 2014 01:58:06 -0300 Subject: [PATCH 1/2] Store the selected entry when starting a search and use it when sorting the files --- src/search/FindInFiles.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/search/FindInFiles.js b/src/search/FindInFiles.js index adf2b75ea6c..2169c73ab90 100644 --- a/src/search/FindInFiles.js +++ b/src/search/FindInFiles.js @@ -90,6 +90,9 @@ define(function (require, exports, module) { /** @type {Panel} Bottom panel holding the search results. Initialized in htmlReady() */ var searchResultsPanel; + /** @type {Entry} the File selected on the initial search */ + var selectedEntry; + /** @type {number} The index of the first result that is displayed */ var currentStart = 0; @@ -260,9 +263,7 @@ define(function (require, exports, module) { * Sorts the file keys to show the results from the selected file first and the rest sorted by path */ function _sortResultFiles() { - var selectedEntry = ProjectManager.getSelectedItem().fullPath; searchFiles = Object.keys(searchResults); - searchFiles.sort(function (key1, key2) { if (selectedEntry === key1) { return -1; @@ -938,6 +939,7 @@ define(function (require, exports, module) { dialog = new FindInFilesDialog(); searchResults = {}; + selectedEntry = ProjectManager.getSelectedItem().fullPath; currentStart = 0; currentQuery = ""; currentQueryExpr = null; From 6dd0ccecd58311064c8d2b8407cfaba649ceb21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Tue, 4 Mar 2014 19:19:45 -0300 Subject: [PATCH 2/2] Only store the selected entry when there is something selected --- src/search/FindInFiles.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/search/FindInFiles.js b/src/search/FindInFiles.js index 2169c73ab90..6673efc93fc 100644 --- a/src/search/FindInFiles.js +++ b/src/search/FindInFiles.js @@ -936,10 +936,15 @@ define(function (require, exports, module) { initialString = dialog.getDialogTextField().val(); dialog._close(true); } - + + // Save the currently selected file's fullpath if there is one selected and if it is a file + var selectedItem = ProjectManager.getSelectedItem(); + if (selectedItem && !selectedItem.isDirectory) { + selectedEntry = selectedItem.fullPath; + } + dialog = new FindInFilesDialog(); searchResults = {}; - selectedEntry = ProjectManager.getSelectedItem().fullPath; currentStart = 0; currentQuery = ""; currentQueryExpr = null;