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: fix some issues
Adorian Dorancb47e5c50e23
diff --git a/apps/client/src/widgets/buttons/show_all_notes_button.css b/apps/client/src/widgets/buttons/show_all_notes_button.cssindex f2992dc895..477bdb808b 100644--- a/apps/client/src/widgets/buttons/show_all_notes_button.css+++ b/apps/client/src/widgets/buttons/show_all_notes_button.css@@ -28,7 +28,6 @@height: calc(var(--tab-bar-height) + var(--classic-toolbar-height) - 42px);}- /* `button.btn` outranks `#left-pane .btn:not(.btn-primary)` in style.css. */> button.btn {display: flex;flex: 1 1 auto;diff --git a/packages/codemirror/src/extensions/trilium_log_highlighter.spec.ts b/packages/codemirror/src/extensions/trilium_log_highlighter.spec.tsindex 1646b4017f..75315ebde4 100644--- a/packages/codemirror/src/extensions/trilium_log_highlighter.spec.ts+++ b/packages/codemirror/src/extensions/trilium_log_highlighter.spec.ts@@ -284,6 +284,20 @@ describe("triliumLogHighlighter", () => {expect(logDecorationsOf(s)).toBe(logDecorations);});+ it("keeps the SQL marks through a reconfigure that leaves the code theme alone", () => {+ // `performFind()` reconfigures the editor on every search.+ const doc = "00:10:01.540 Slow query took 78ms: SELECT 1";+ const search = new Compartment();+ const s = sqlState(doc, [ syntaxHighlighting(classHighlighter), search.of([]) ]);+ const sets = s.facet(EditorView.decorations);+ const next = s.update({ effects: search.reconfigure(EditorView.lineWrapping) }).state;++ expect(sliceOf(doc, decorationsOf(next), "tok-keyword")).toBe("SELECT");+ const nextSets = next.facet(EditorView.decorations);+ expect(nextSets).toHaveLength(sets.length);+ expect(nextSets.every((set, index) => set === sets[index])).toBe(true);+ });+it("keeps every decoration set unless the document or the configuration changes", () => {const doc = "00:10:01.540 Slow query took 78ms: SELECT 1";for (const s of [ state(doc), sqlState(doc) ]) {diff --git a/packages/codemirror/src/extensions/trilium_log_highlighter.ts b/packages/codemirror/src/extensions/trilium_log_highlighter.tsindex b9bdd411f1..9feb4ce02d 100644--- a/packages/codemirror/src/extensions/trilium_log_highlighter.ts+++ b/packages/codemirror/src/extensions/trilium_log_highlighter.ts@@ -1,7 +1,7 @@import { highlightingFor, type Language } from "@codemirror/language";import { type EditorState, type Extension, RangeSetBuilder, StateField } from "@codemirror/state";import { Decoration, type DecorationSet, EditorView } from "@codemirror/view";-import { type Highlighter, highlightTree } from "@lezer/highlight";+import { type Highlighter, highlightTree, type Tag } from "@lezer/highlight";import { decorateSearchQuery, searchHighlightTheme } from "./trilium_search_highlighter.js";@@ -128,12 +128,17 @@ interface SqlStatement {text: string;}-interface LogHighlights {+interface SqlHighlights {+ /** The tokens of the statements, with the classes of the active code theme. */+ sql: DecorationSet;+ /** The class of each tag set in `sql`, in the code theme that `sql` was built with. */+ styles: Map<readonly Tag[], string | null>;+}++interface LogHighlights extends SqlHighlights {log: DecorationSet;/** The statements in the highlighted lines; empty without a SQL language. */statements: SqlStatement[];- /** The tokens of `statements`, with the classes of the active code theme. */- sql: DecorationSet;}/**@@ -145,11 +150,11 @@ export function triliumLogHighlighter(sqlLanguage: Language | null = null): Extecreate: (state) => buildHighlights(state, sqlLanguage),update(highlights, tr) {if (tr.docChanged) return buildHighlights(tr.state, sqlLanguage);- // A new code theme changes the token classes. `performFind()` also reconfigures, on- // every search, so a reconfigure rebuilds only the SQL marks.- if (tr.reconfigured && sqlLanguage) {- const sql = buildSqlDecorations(tr.state, highlights.statements, sqlLanguage);- return { ...highlights, sql };+ // `performFind()` reconfigures on every search, so a reconfigure rebuilds the SQL marks+ // only when the code theme gives one of their tag sets another class.+ if (tr.reconfigured && sqlLanguage && isRestyled(tr.state, highlights.styles)) {+ const sql = buildSqlHighlights(tr.state, highlights.statements, sqlLanguage);+ return { ...highlights, ...sql };}return highlights;},@@ -177,25 +182,38 @@ function buildHighlights(state: EditorState, sqlLanguage: Language | null): LogHblockLine = decorateLine(builder, doc.line(n), blockLine, collectedStatements);}- return {- log: builder.finish(),- statements,- sql: sqlLanguage ? buildSqlDecorations(state, statements, sqlLanguage) : Decoration.none- };+ const sql = sqlLanguage+ ? buildSqlHighlights(state, statements, sqlLanguage)+ : { sql: Decoration.none, styles: new Map() };+ return { log: builder.finish(), statements, ...sql };}/** Marks the tokens of each statement with the classes that the active code theme gives them. */-function buildSqlDecorations(+function buildSqlHighlights(state: EditorState, statements: SqlStatement[], language: Language-): DecorationSet {+): SqlHighlights {const builder = new RangeSetBuilder<Decoration>();- const highlighter: Highlighter = { style: (tags) => highlightingFor(state, tags) };+ const styles: SqlHighlights["styles"] = new Map();+ const highlighter: Highlighter = {+ style(tags) {+ if (!styles.has(tags)) styles.set(tags, highlightingFor(state, tags));+ return styles.get(tags) ?? null;+ }+ };for (const { from, text } of statements) {highlightTree(language.parser.parse(text), highlighter, (start, end, classes) => {builder.add(from + start, from + end, sqlTokenMark(classes));});}- return builder.finish();+ return { sql: builder.finish(), styles };+}++/** Whether the code theme of `state` gives a tag set in `styles` another class. */+function isRestyled(state: EditorState, styles: SqlHighlights["styles"]) {+ for (const [ tags, classes ] of styles) {+ if (highlightingFor(state, tags) !== classes) return true;+ }+ return false;}function sqlTokenMark(classes: string) {