mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Use unicode-aware comparisons for user-visible strings.
Summary: - Switch code that compares user strings to use localeCompare() based on Intl.Collator. - Use en-US locale for now. (Ideally should be a document property.) - Note that with this change, sorting is also becoming case-insensitive (which seems an improvement) - Updated a sorted test fixture - Updated a browser test with lots of unicode to expect different order. - Added a bit of unicode to test ordering in Reference autocomplete dropdown. Test Plan: Fixed / updated tests Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2758
This commit is contained in:
@@ -444,6 +444,11 @@ export function nativeCompare<T>(a: T, b: T): number {
|
||||
return (a < b ? -1 : (a > b ? 1 : 0));
|
||||
}
|
||||
|
||||
// TODO: In the future, locale should be a value associated with the document or the user.
|
||||
export const defaultLocale = 'en-US';
|
||||
export const defaultCollator = new Intl.Collator(defaultLocale);
|
||||
export const localeCompare = defaultCollator.compare;
|
||||
|
||||
/**
|
||||
* A copy of python`s `setdefault` function.
|
||||
* Sets key in mapInst to value, if key is not already set.
|
||||
|
||||
Reference in New Issue
Block a user