fix: numeric sorting of tool macros in spoolman card#1763
fix: numeric sorting of tool macros in spoolman card#1763pedrolamas merged 5 commits intofluidd-core:developfrom
Conversation
Signed-off-by: wasikuss <wasikuss@gmail.com>
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
There was a problem hiding this comment.
Pull request overview
Fixes numeric sorting of tool macros in the Spoolman card dropdown, ensuring names like "T1", "T2", "T10" sort correctly (1, 2, 10) instead of alphabetically (1, 10, 2).
- Replaced simple case-insensitive string comparison with
localeCompareusingnumeric: trueoption for natural number sorting
| .filter((macro): macro is MacroWithSpoolId => macro.variables != null && 'spool_id' in macro.variables) | ||
| .sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase())) | ||
| .sort((a, b) => a.name.localeCompare(b.name, undefined, { | ||
| sensitivity: 'accent', |
There was a problem hiding this comment.
The sensitivity: 'accent' option makes the sort case-sensitive, which changes the existing behavior. The original code used toLowerCase() to ensure case-insensitive sorting. To maintain case-insensitive sorting while adding numeric support, use sensitivity: 'base' instead of sensitivity: 'accent'.
With 'accent': "Tool 10" would sort differently from "tool 10"
With 'base': "Tool 10" and "tool 10" are treated as equal (case-insensitive)
| sensitivity: 'accent', | |
| sensitivity: 'base', |
There was a problem hiding this comment.
I've removed the sensitivity as this is not necessary; when using numeric: true, that will already cause a case-insensitive comparison.
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
The drop-down for changing spools on multi tool machine is sorted without taking care of numbers.
Before

After:

Signed-off-by: Krzysztof Wasilewski wasikuss@gmail.com