Skip to content

feat: default sort setting - #690

Open
dolsem wants to merge 1 commit into
josh-berry:masterfrom
dolsem:master
Open

feat: default sort setting#690
dolsem wants to merge 1 commit into
josh-berry:masterfrom
dolsem:master

Conversation

@dolsem

@dolsem dolsem commented May 2, 2026

Copy link
Copy Markdown

This PR adds a setting to specify sort order when inserting multiple tabs. This is useful when stashing windows with a large number of tabs.

image

Please let me know if you have any concerns / need anything changed for this PR to get merged.

@josh-berry josh-berry left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for sending this over! I've left you some comments below; let me know if you have any questions.

Also, if you wrote any part of this code with AI, please make sure to add an appropriate Co-Authored-By line to your commit and PR description.

Comment thread src/model/options.ts
// When stashing multiple tabs, what order should the tabs have inside the
// destination group?
multi_tab_stash_sort: {
default: "date_added",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default should be to preserve the existing behavior—that is, preserve the order of items as provided.

Comment thread src/model/index.ts
Comment on lines +128 to +132
const tabStashSortCollator = new Intl.Collator(undefined, {
usage: "sort",
sensitivity: "base",
numeric: true,
});

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is existing sorting functionality / existing collators already defined in bookmarks.ts. Let's leverage those rather than redefining them. (This will also take care of the issue you have sorting URLs—you cannot treat them like strings because they are structured data; they need to be sorted domain-first.)

Comment thread src/model/index.ts

/** Returns a copy of the items in the user's preferred order for insertion
* when stashing multiple tabs. */
sortItemsForMultiTabStashInsertion<T extends StashItem>(items: T[]): T[] {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sortItemsForInsertion feels like a cleaner name; putting "Tab Stash" in the name seems redundant.

Comment thread src/model/index.ts
toFolder: Bookmarks.Folder;
toIndex?: number;
allowDuplicates?: boolean;
insertionOrder?: StashItem[];

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant to items; why do we need to pass the list of items twice?

(Did you generate this PR with AI?)

Comment thread src/model/index.ts
Comment on lines +850 to +855
await this.bookmarks.move(
ordered_nodes[i],
to_folder,
insertion_start + i,
);
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this is redundant; the existing code already inserts items in the order they are provided in items. We should not be touching bookmarks more than necessary (your addition now moves each bookmark twice), because if the user has other extensions installed or sync happens during a move, it increases the risk of us tripping various Firefox edge cases that can cause sync conflicts or get the user's bookmarks DB into an inconsistent state.

All you need to do is update the callers of putItemsInFolder() to pass the items in in the order you want them to be sorted.

This also considerably simplifies the test cases you need to write, because you essentially only need to test your sort function and that the setting you added is applied correctly.

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.

2 participants