Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
Bug 667314 - Don't loop infinitely when closing the selected tab in t…
Browse files Browse the repository at this point in the history
…he Ctrl+Tab panel. r=gavin
  • Loading branch information
daogottwald committed Jul 5, 2011
1 parent 7f870f7 commit 431ee81
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
19 changes: 9 additions & 10 deletions browser/base/content/browser-tabPreviews.js
Expand Up @@ -215,15 +215,17 @@ var ctrlTab = {
if (this._tabList)
return this._tabList;

let list = gBrowser.visibleTabs;

if (this._closing)
this.detachTab(this._closing, list);
// Using gBrowser.tabs instead of gBrowser.visibleTabs, as the latter
// exlcudes closing tabs, breaking the following loop in case the the
// selected tab is closing.
let list = Array.filter(gBrowser.tabs, function (tab) !tab.hidden);

// Rotate the list until the selected tab is first
while (!list[0].selected)
list.push(list.shift());

list = list.filter(function (tab) !tab.closing);

if (this.recentlyUsedLimit != 0) {
let recentlyUsedTabs = this._recentlyUsedTabs;
if (this.recentlyUsedLimit > 0)
Expand Down Expand Up @@ -370,11 +372,10 @@ var ctrlTab = {
else
this._recentlyUsedTabs.push(aTab);
},
detachTab: function ctrlTab_detachTab(aTab, aTabs) {
var tabs = aTabs || this._recentlyUsedTabs;
var i = tabs.indexOf(aTab);
detachTab: function ctrlTab_detachTab(aTab) {
var i = this._recentlyUsedTabs.indexOf(aTab);
if (i >= 0)
tabs.splice(i, 1);
this._recentlyUsedTabs.splice(i, 1);
},

open: function ctrlTab_open() {
Expand Down Expand Up @@ -498,10 +499,8 @@ var ctrlTab = {
return;
}

this._closing = aTab;
this._tabList = null;
this.updatePreviews();
this._closing = null;

if (this.selected.hidden)
this.advanceFocus(false);
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/tabbrowser.xml
Expand Up @@ -96,7 +96,7 @@
<getter><![CDATA[
return Array.filter(this.tabs, function(tab) {
return !tab.hidden && !tab.closing;
}, this);
});
]]></getter>
</property>
<field name="mURIFixup" readonly="true">
Expand Down
10 changes: 10 additions & 0 deletions browser/base/content/test/browser_ctrlTab.js
Expand Up @@ -28,6 +28,16 @@ function test() {
releaseCtrl();
}

{ // test for bug 667314
let tabs = gBrowser.tabs.length;
pressCtrlTab();
pressCtrlTab(true);
EventUtils.synthesizeKey("w", { ctrlKey: true });
is(gBrowser.tabs.length, tabs - 1, "Ctrl+Tab -> Ctrl+W removes the selected tab");
releaseCtrl();
}

gBrowser.addTab();
checkTabs(3);
ctrlTabTest([2, 1, 0], 9, 1);

Expand Down

0 comments on commit 431ee81

Please sign in to comment.