Skip to content

Commit

Permalink
implement react_onTabRemoved
Browse files Browse the repository at this point in the history
  • Loading branch information
cxw42 committed Dec 18, 2020
1 parent 0ab7819 commit 0ffe713
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
35 changes: 30 additions & 5 deletions app/win/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,13 +728,13 @@ me.updateTabIndexValues = function updateTabIndexValues(win_nodey, as_open = [])
}
}

let old_hash = D.windows.by_node_id(win_node.id, 'ordered_url_hash'); //DEBUG
//let old_hash = D.windows.by_node_id(win_node.id, 'ordered_url_hash'); //DEBUG

// TODO do we need this, or can we use a dirty flag to avoid
// recomputing?
me.updateOrderedURLHash(win_node.id);

let new_hash = D.windows.by_node_id(win_node.id, 'ordered_url_hash'); //DEBUG
//let new_hash = D.windows.by_node_id(win_node.id, 'ordered_url_hash'); //DEBUG
//log.trace(`win ${win_node.id} hash from ${old_hash} to ${new_hash}`); //DEBUG
} //updateTabIndexValues

Expand Down Expand Up @@ -1126,12 +1126,12 @@ me.react_onTabCreated = function(win_vorny, ctab) {
tabvn = me.vnRezTab(winvn.node_id);

if(!tabvn.node_id) {
log.debug({"<M> Could not create record for ctab":ctab, winvn});
log.debug({"Could not create record for ctab":ctab, winvn});
me.eraseTab(tabvn);
return false;
}
if(!me.markTabAsOpen(tabvn.val, ctab)) {
log.debug({"<M> Could not mark tab as open":ctab, tabvn});
log.debug({"Could not mark tab as open":ctab, tabvn});
me.eraseTab(tabvn);
return false;
}
Expand Down Expand Up @@ -1232,7 +1232,32 @@ me.react_onTabMoved = function(cwinid, ctabid, cidx_from, cidx_to) {
/// @param cwinid The Chrome window ID of the window the tab is being removed from
/// @return True on success; a string error message on failure
me.react_onTabRemoved = function react_onTabRemoved(ctabid, cwinid) {
return "not yet implemented";
let winvn = me.vn_by_cid(cwinid, K.IT_WIN);
if(!winvn.val) return `Window ${cwinid} not found`;

let tabvn = me.vn_by_cid(ctabid, K.IT_TAB);

// See if it's a tab we have already marked as removed. If so,
// whichever code marked it is responsible, and we're off the hook.
if(!tabvn.val || tabvn.val.tab_id === K.NONE) {
log.debug({"Bailing, but it's probably OK - no tab val for ctab":ctabid, tabvn, cwinid});
return true;
}

// ...but if we have not marked it as removed and a node is missing,
// something has gone wrong.
if(!tabvn.node_id) {
return `Bailing - no node_id for ctab ${ctabid} in window ${cwinid} (${JSON.serialize(tabvn)}`;
}

// Remove the tab
log.debug({'Removing value and entry for ctab':ctabid, tabvn, cwinid});
me.eraseTab(tabvn, 'chrome');

// Refresh the tab.index values for the remaining tabs
me.updateTabIndexValues(winvn.node_id);

return true;
} // }}}2

// onTabDetached() {{{2
Expand Down
11 changes: 11 additions & 0 deletions t/spec/app-win-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ describe('app/win/model', function() {
// Mock
let winvn = makeFakeWindow(thetest[0]);
let tabvn = findTabInWindow(winvn, thetest[1]);
const tab_node_id = tabvn.node_id;

// Do the work
const ok =
Expand All @@ -718,6 +719,9 @@ describe('app/win/model', function() {
// Check it
expect(tabvn.val.win_id).toBe(K.NONE);
expect(tabvn.val.index).toBe(K.NONE);
const tab_node = T.treeobj.get_node(tab_node_id);
expect(tab_node).toBeTruthy();
expect(tab_node.parent).toBe(T.holding_node_id);
expectWindowState(winvn, thetest[2]);
expect(M.eraseWin(winvn)).toBeTruthy();
});
Expand Down Expand Up @@ -758,6 +762,7 @@ describe('app/win/model', function() {
// Attach it to a window
let tabvn = M.vnRezTab(winvn);
expect(tabvn.val).toBeTruthy();
const tab_node_id = tabvn.node_id;
expect(M.markTabAsOpen(tabvn, ctab)).toBeTruthy();

// Detach it by hand. Excerpted from app/win/main_tl:tabOnDetached().
Expand All @@ -774,7 +779,13 @@ describe('app/win/model', function() {
// Check it
expect(tabvn.val.win_id).toBe(winvn.val.win_id);
expect(tabvn.val.index).toBe(ctab.index);

const tab_node = T.treeobj.get_node(tab_node_id);
expect(tab_node).toBeTruthy();
expect(tab_node.parent).not.toBe(T.holding_node_id);

expectWindowState(winvn, thetest[3]);

expect(M.eraseWin(winvn)).toBeTruthy();
});
} //foreach testcase
Expand Down

0 comments on commit 0ffe713

Please sign in to comment.