Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/text editor/tables: fix an issue
Adorian Dorane4052c252e09
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Tables.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Tables.htmlindex 00f8971bc8..9f97b7ae8d 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Tables.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Tables.html@@ -192,7 +192,8 @@ src="3_Tables_image.png" width="384" height="100"><tr><td>Text</td><td>Anything else.</td>- <td>Alphabetically, with numbers inside the text in numeric order (<code>Item 9</code> before <code>Item 10</code>).</td>+ <td>Alphabetically, ignoring case, with numbers inside the text in numeric+ order (<code>Item 9</code> before <code>Item 10</code>). Accents count, so <code>a</code> and <code>á</code> differ.</td></tr><tr><td>Empty</td>@@ -203,8 +204,10 @@ src="3_Tables_image.png" width="384" height="100"></table></figure><p>Ascending order puts times first, then dates, numbers and text. Descending- order reverses it. Empty cells go last in both directions, and rows with- equal values keep their relative order.</p>+ order reverses it. Empty cells go last in both directions.</p>+<p>Numbers, dates and times with the same value are ordered by their text,+ so <code>5 apples</code> comes before <code>5 pears</code>. Rows whose cells+ hold the same text, ignoring case, keep their relative order.</p><ul><li>Dates are also recognized in the formats of the note's language, suchas <code>30.09.2026</code> or <code>30. September 2026</code> for German, anddiff --git a/docs/User Guide/User Guide/Note Types/Text/Tables.md b/docs/User Guide/User Guide/Note Types/Text/Tables.mdindex 6160ffda79..40e101cac3 100644--- a/docs/User Guide/User Guide/Note Types/Text/Tables.md+++ b/docs/User Guide/User Guide/Note Types/Text/Tables.md@@ -97,10 +97,12 @@ Each cell is read as plain text, so formatting does not affect the order. Triliu| Time | `15:02`, `15:02:38`, `3:02 PM` | The time of day. || Date | `2026-09-30`, `2026-09-30 15:02`, `30 September 2026`, `Wednesday, 30 September 2026`, `2026-09-30T15:02:38+03:00` | The date and time. || Number | `12`, `-3.5`, `1,234.56`, `$ 12.04`, `21 RON`, `24.5m` | The numeric value. |-| Text | Anything else. | Alphabetically, with numbers inside the text in numeric order (`Item 9` before `Item 10`). |+| Text | Anything else. | Alphabetically, ignoring case, with numbers inside the text in numeric order (`Item 9` before `Item 10`). Accents count, so `a` and `á` differ. || Empty | An empty cell, or one holding only spaces. | Not compared. Empty cells always go last. |-Ascending order puts times first, then dates, numbers and text. Descending order reverses it. Empty cells go last in both directions, and rows with equal values keep their relative order.+Ascending order puts times first, then dates, numbers and text. Descending order reverses it. Empty cells go last in both directions.++Numbers, dates and times with the same value are ordered by their text, so `5 apples` comes before `5 pears`. Rows whose cells hold the same text, ignoring case, keep their relative order.* Dates are also recognized in the formats of the note's language, such as `30.09.2026` or `30. September 2026` for German, and in the format chosen in <a class="reference-link" href="../../Basic%20Concepts%20and%20Features/UI%20Elements/Options.md">Options</a> → _Text Notes_ → _Editor_ → _Date/time format_ for [inserting the date and time](Insert%20buttons.md).* A number can start with a currency symbol, such as `$`, `€` or `£`. Whatever follows the number, such as a unit, is ignored, so units are not converted: `1 km` sorts before `500 m`. A cell that starts with letters, such as `RON 21`, is text.diff --git a/packages/commons/src/lib/auto_sort.spec.ts b/packages/commons/src/lib/auto_sort.spec.tsindex 155ceda1f4..c46cf1bbf7 100644--- a/packages/commons/src/lib/auto_sort.spec.ts+++ b/packages/commons/src/lib/auto_sort.spec.ts@@ -181,6 +181,18 @@ describe("autoSort", () => {expect(sort(["Äpple", "Zebra"], { locale: "sv" })).toEqual(["Zebra", "Äpple"]);});+ it("ignores case but not accents in text, in both directions", () => {+ for (const isDescending of [false, true]) {+ const options = { locale: "en", isDescending };+ expect(sort(["Apple", "apple"], options)).toEqual(["Apple", "apple"]);+ expect(sort(["apple", "Apple"], options)).toEqual(["apple", "Apple"]);+ expect(sort(["5 Apples", "5 apples"], options)).toEqual(["5 Apples", "5 apples"]);+ }+ expect(sort(["á", "a", "b"], { locale: "en" })).toEqual(["a", "á", "b"]);+ expect(sort(["a", "á", "b"], { locale: "en", isDescending: true }))+ .toEqual(["b", "á", "a"]);+ });+it("uses the decimal mark of the locale", () => {expect(sort(["1.500", "2"], { locale: "en" })).toEqual(["1.500", "2"]);expect(sort(["1.500", "2"], { locale: "de" })).toEqual(["2", "1.500"]);diff --git a/packages/commons/src/lib/auto_sort.ts b/packages/commons/src/lib/auto_sort.tsindex f99a0bf33b..1fbad7b4f2 100644--- a/packages/commons/src/lib/auto_sort.ts+++ b/packages/commons/src/lib/auto_sort.ts@@ -22,8 +22,8 @@ export interface AutoSortValue {/*** Sorts strings whose type is not known in advance, such as table cells or lines. Each value is* detected as a time, a date, a number, text or empty. Ascending order is times, dates, numbers,- * then text; descending order reverses it. Empty values are always last. Equal values keep their- * order. Typed data, such as attributes, has its own comparators instead.+ * then text; descending order reverses it. Empty values are always last. Text ignores case, and+ * equal values keep their order. Typed data, such as attributes, has its own comparators instead.*/export function autoSort<T>(items: readonly T[],@@ -32,7 +32,8 @@ export function autoSort<T>(): T[] {const locale = resolveLocale(options.locale);const classify = createClassifier(locale, options.dateFormats ?? []);- const collator = new Intl.Collator(locale, { numeric: true });+ // Case-insensitive but accent-sensitive, as spreadsheets sort by default.+ const collator = new Intl.Collator(locale, { numeric: true, sensitivity: "accent" });const direction = options.isDescending ? -1 : 1;return items