From 9c95126b98a5660f55f1213b4d6a17c3d9169828 Mon Sep 17 00:00:00 2001 From: Sina Siadat Date: Mon, 28 Sep 2015 03:59:12 +0330 Subject: [PATCH] Revert original tab ordering when cancelled. --- background.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/background.js b/background.js index a726649..ee2edd6 100644 --- a/background.js +++ b/background.js @@ -6,6 +6,7 @@ var FF_MOVE_TAB_TO_FIRST = true; var FF_MOVE_TAB_TO_FIRST_TO_CURRENT_WINDOW = false; var ffHistory = []; var ffCurrentWindowId; +var ffTabsOnStart = []; function ffEscapeRegExp(str) { return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); @@ -200,9 +201,13 @@ function ffSearchFor(text, callback) { * } */ + if(ffTabsOnStart.length === 0) { + ffTabsOnStart = matching_tabs.slice(0, 200).map(function(tab) { return {id: tab.id, index: tab.index}; }); + } + matching_tabs.slice(0, 200).forEach(function(tab, i) { if(FF_MOVE_TAB_TO_FIRST_TO_CURRENT_WINDOW && ffCurrentWindowId) { - // move all to current window + // move one by one to current window chrome.tabs.move(tab.id, {index: i, windowId: ffCurrentWindowId}); } else { // move one by one @@ -237,6 +242,21 @@ chrome.omnibox.onInputChanged.addListener( } ); +chrome.omnibox.onInputCancelled.addListener( + // TODO this is called even when user presses UP/Down arrows. + function() { + // revert tab order (one by one) + ffTabsOnStart.sort(function(tab1, tab2) { + if(tab1.index < tab2.index) return 1; + if(tab1.index > tab2.index) return -1; + return 0; + }).forEach(function(tab, i) { + chrome.tabs.move(tab.id, {index: tab.index}); + }); + ffTabsOnStart = []; + } +); + chrome.omnibox.onInputEntered.addListener( function(text) { if(FF_DEBUGGING) {