I want to find neighbors for a tab that's being closed, so I'm trying to match the tab I get in a tab closing callback to the tab list I iterate from the Lister.
But then they don't match even if their IDs are the same. Why are this considered different objects, but more importantly, is there a "more direct" way to compare tabs from these two sources than doing +0?
function OnCloseTab(closeTabD) {
var sV = Script.vars, sC = Script.config, DC = DOpus.Create
,tab = closeTabD.tab;
var tab_lr = getTabNeighbors(tab);
}
function getTabNeighbors(tab) {
var sV=Script.vars, sC=Script.config, DC=DOpus.Create,
L = tab.lister;
var tabs = tab.right ? L.tabsright : L.tabsleft;
var tab_path = tab.path;
var tab_left, tab_right;
for (var i=0;i<tabs.count;i++) {
if (tabs[i] === tab) { // fails
// if ((tabs[i]+0) === (tab+0)) { //works
DOpus.Output('FOUND a match');
}
}
return [tab_left,tab_right]
}
You say you want to compare the IDs, but in your example, you're trying to compare the entire object. Appending "" should be enough. if (tabs[i] + "" === tab + "")
(If you have closed a tab, I imagine you won't find any others with the same ID since they are unique. Perhaps what you mean by "neighbors" is those with the same path?)
sure, but I don't get why the objects are different if the tab is the same?
The tab isn't closed yet at the time the callback is called, so I'm looking for the same tab in the tablist to find its index and from its index its neighbors (I mean tab to the left/to the right)
Ok, then wouldn't it be better to have some .id property returning an int so you can get this value?
I've also had similar issue comparing tab.path, which I thought was a string due to Path [Directory Opus Manual] saying that it's default value is a string (so I somehow thought it would magically fetch the default value), so an explicit value would've resolved this confusion. Or maybe there is a better mechanism of getting default value (the +"" is weird)?