Skip to content

feat: sort theme and dropdown options case-insensitively#23

Open
adamalston wants to merge 4 commits intozerebos:mainfrom
adamalston:22-sort
Open

feat: sort theme and dropdown options case-insensitively#23
adamalston wants to merge 4 commits intozerebos:mainfrom
adamalston:22-sort

Conversation

@adamalston
Copy link

@adamalston adamalston commented May 19, 2025

Closes #22

const {type, id, value} = setting;

if ((type === "dropdown" || type === "theme") && Array.isArray(setting.options)) {
setting.options = [...setting.options].sort((a, b) => {
Copy link
Owner

Choose a reason for hiding this comment

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

Why recreate the array rather than sort in place?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds case-insensitive alphabetical sorting to dropdown and theme options to improve the user experience when selecting values from these lists.

Changes:

  • Added sorting logic for dropdown and theme options that handles both string options and object options (with name/value pairs) case-insensitively
  • Refactored the initialization loop to use destructured variables for better readability

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 16 to 23
if ((type === "dropdown" || type === "theme") && Array.isArray(setting.options)) {
setting.options.sort((a, b) => {
const normalizedA = (typeof a === "string" ? a : a.name).toLowerCase();
const normalizedB = (typeof b === "string" ? b : b.name).toLowerCase();

return normalizedA.localeCompare(normalizedB);
});
}
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The sorting is performed during module initialization, but theme options are populated asynchronously via fetchThemeFiles() in settings.ts (line 119-124). This means theme files fetched from the GitHub API will be added to the options array after this sort runs, leaving them unsorted. Consider either:

  1. Moving the sort logic to run after theme options are loaded (e.g., in the fetchThemeFiles().then() callback)
  2. Implementing reactive sorting that triggers whenever options are modified
  3. Sorting the theme names before pushing them in the fetchThemeFiles callback

Copilot uses AI. Check for mistakes.
@zerebos
Copy link
Owner

zerebos commented Jan 14, 2026

I'm assuming you've tested this and the asynchronous issue copilot is referencing is not relevant?

@adamalston
Copy link
Author

What Copilot is mentioning is likely a better solution.

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.

Color theme select options are not sorted in a case-insensitive manner

2 participants