Skip to content

Commit

Permalink
Save correct selected tab for windows with private tabs
Browse files Browse the repository at this point in the history
(improvement for #36)
  • Loading branch information
Infocatcher committed Apr 19, 2013
1 parent c85241f commit 332ddcb
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,19 +566,32 @@ var windowsObserver = {
)
return;
var state = JSON.parse(stateString);
var changed = false;
var sessionChanged = false;
state.windows.forEach(function(windowState) {
if(windowState.isPrivate) // Browser should ignore private windows itself
return;
windowState.tabs = windowState.tabs.filter(function(tabState) {
var windowChanged = false;
var oldSelected = windowState.selected || 1;
var newSelected;
var newIndex = 0;
var tabs = windowState.tabs = windowState.tabs.filter(function(tabState, i) {
var isPrivate = "attributes" in tabState && this.privateAttr in tabState.attributes;
if(isPrivate)
changed = true;
sessionChanged = windowChanged = true;
else {
++newIndex;
if(!newSelected && i + 1 >= oldSelected)
newSelected = newIndex;
}
return !isPrivate;
}, this);
//~ todo: update windowState.selected ?
if(windowChanged) {
windowState.selected = newSelected || tabs.length;
//_log("Correct selected tab: " + oldSelected + " => " + newSelected + " => " + windowState.selected);
}
//~ todo: what to do with empty window without tabs ?
}, this);
if(!changed)
if(!sessionChanged)
return;
var newStateString = JSON.stringify(state);
if(newStateString == stateString)
Expand Down

0 comments on commit 332ddcb

Please sign in to comment.