Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize moving tabs inside the same window #1338

Merged
merged 2 commits into from
Dec 8, 2023
Merged

Optimize moving tabs inside the same window #1338

merged 2 commits into from
Dec 8, 2023

Conversation

Lej77
Copy link
Contributor

@Lej77 Lej77 commented Oct 29, 2023

I noticed that moving all tabs inside a window to a new panel could be quite slow so I took a look at the code in order to optimize it. I suspect that it was the left over TODO: Do not call this fn if: all tabs go one after another and srcIndex === dstIndex that was the cause of my issue so I implemented a check for that condition and when I ran the code in the debugger the browser.tabs.move function was indeed not called when moving all tabs to a new panel.

@mbnuqw
Copy link
Owner

mbnuqw commented Oct 31, 2023

Thank you.

canSkipMove gets the true value when you drag and drop the tab to one position down/up, so native tabs are not updated. This happens because the local state of tabs has been updated at this (line 290) moment, and the tabs[0].index has its final (as after the move) value.

We need to gather all needed info before the change of the local state of tabs:

const oneAfterAnother = tabs.every((tab, ix) => ix === 0 || tab.index === tabs[ix - 1].index + 1)
const srcIndex = tabs[0].index
// ^ Somewhere before line ~166

And check if we canSkipMove using this info (instead of 290..294):

const samePosition = srcIndex === tabs[0].index
const canSkipMove = oneAfterAnother && samePosition

@Lej77
Copy link
Contributor Author

Lej77 commented Oct 31, 2023

My bad, should have thought about the internal state updating. Anyway, I made the suggested changes and I have checked that the updated code does actually move the tabs in the native tab bar. So I think it should work now!

@mbnuqw mbnuqw merged commit a58b178 into mbnuqw:v5 Dec 8, 2023
@Lej77 Lej77 deleted the patch-1 branch December 8, 2023 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants