Skip to content

Commit

Permalink
Revert original tab ordering when cancelled.
Browse files Browse the repository at this point in the history
  • Loading branch information
siadat committed Sep 28, 2015
1 parent fd5d35d commit 9c95126
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, "\\$&");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9c95126

Please sign in to comment.