Skip to content

Sort tabs with less steps#2

Open
piroor wants to merge 4 commits intomonomon:masterfrom
piroor:sort-tabs-with-less-steps
Open

Sort tabs with less steps#2
piroor wants to merge 4 commits intomonomon:masterfrom
piroor:sort-tabs-with-less-steps

Conversation

@piroor
Copy link
Copy Markdown

@piroor piroor commented Apr 18, 2019

Hello,

Currently this addon tries to move all tabs always, even if they don't need to be moved. This approach may cause some troubles:

  • It may produce too much tab moves. When there are too many tabs (for example, over 1000+) it may take much time.
  • It may scramble tabs unexpectedly and unnecessarily. It is critically dangerous on some kinds of addons (like Tree Style Tab).

So, instead only minimum tabs should be moved based on the algorithm of "diff". This PR contains a ported version of diff and changes to move tabs based on the calculated difference. The main logic is ported from Tree Style Tab, and this PR is based on my another PR for Firefox Multi-Account Containers.

How about this change?

@piroor
Copy link
Copy Markdown
Author

piroor commented Apr 18, 2019

Here are some additional information for reviewing:

  • The largest addition differ.js is a ported version from the diff module of npm. I just modified it to remove needless codes for this usecase.
  • The differ detects three type differences: "added", "removed", and "unchanged". Rearranging of tabs is based on a logic:
    1. Prepare three arrays: initial order (beforeIds), final order (afterIds), and the current order (currentIds: this is required because tabs.move() is asynchronous and we need to track the order of tabs after tab moves.)
    2. Calculate differences between the initial order and the final order.
    3. Extract only "added" differences. Any "removed" difference should be ignored, because those tabs are moved with corresponding "addded" differences. Of course there is no removed tab while while rearranging.
    4. Calculate destination position of "added" tabs, based on the current order (currentIds).
    5. Move "added" tabs actually via tabs.move().
    6. Update the current order (currentIds) for the next calculation.
    7. Repeat steps 4-7 for all "added" differences.

@piroor
Copy link
Copy Markdown
Author

piroor commented Apr 19, 2019

Here is a blog post describing the logic: How to sort tabs smartly on Firefox addons and Chromium extensions? - Qiita

@perdolka
Copy link
Copy Markdown

@piroor Looks like this addon was abandoned by his author. No updates since 2017. :(

@monomon
Copy link
Copy Markdown
Owner

monomon commented Nov 5, 2020

Thank you for the contribution, this is nice work! Also very cool writeup.

Indeed I had abandoned the addon for a long time, but am back to it. Need a bit of time to integrate your code better, since I made some rearrangements - there is now a background script, in which the sorting happens.

ryokash pushed a commit to ryokash/sort-tabs-advanced that referenced this pull request Jun 15, 2024
…rtup

Made apply autosort on startup + minor changes
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.

3 participants