Skip to content

Commit

Permalink
Select dragged tabs correctly even if there is any hidden tab between…
Browse files Browse the repository at this point in the history
… visible tabs #236
  • Loading branch information
piroor committed Jul 29, 2020
1 parent 5183b05 commit e39d36d
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions webextensions/common/drag-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,36 @@ export default class DragSelection {
return [];
beginningTabs = Array.from(beginningTabs.values());
endTabs = Array.from(endTabs.values());
let startIndex, endIndex;
if (beginningTabs[0].index < endTabs[0].index) { // top to bottom
const startIndex = beginningTabs[beginningTabs.length - 1].index + 1;
const endIndex = endTabs[0].index;
const lastBeginningTab = beginningTabs[beginningTabs.length - 1];
for (let i = 0, maxi = allTabs.length; i < maxi; i++) {
const tab = allTabs[i];
if (tab.id == lastBeginningTab.id)
startIndex = i + 1;
if (tab.id == endTabs[0].id)
endIndex = i;
if (startIndex !== undefined &&
endIndex !== undefined)
break;
}
log(' => top to bottom ', { startIndex, endIndex });
return allTabs.slice(startIndex, endIndex).filter(tab => !tab.hidden);
}
else {
const startIndex = endTabs[endTabs.length - 1].index + 1;
const endIndex = beginningTabs[0].index;
const lastEndTab = endTabs[endTabs.length - 1];
for (let i = 0, maxi = allTabs.length; i < maxi; i++) {
const tab = allTabs[i];
if (tab.id == lastEndTab.id)
startIndex = i + 1;
if (tab.id == beginningTabs[0].id)
endIndex = i;
if (startIndex !== undefined &&
endIndex !== undefined)
break;
}
log(' => bottom to top ', { startIndex, endIndex });
return allTabs.slice(startIndex, endIndex).filter(tab => !tab.hidden);
}
return allTabs.slice(startIndex, endIndex).filter(tab => !tab.hidden);
}

// target can be multiple tabs - for example, collapsed tree of Tree Style Tab.
Expand Down

0 comments on commit e39d36d

Please sign in to comment.