Skip to content

Build your personal knowledge base with Trilium Notes

feat(editor): apply the replacement settings to an already-open note

Elian Doran604eb22e1ae6
diff --git a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
index 14bd45d8d5..4318653411 100644
--- a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
+++ b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
@@ -54,6 +54,17 @@ export default function CKEditorWithWatchdog({ containerRef: externalContainerRe
// Read purely as a rebuild trigger: the value is consumed by buildToolbarConfig() via options.get() at
// editor-creation time, so the editor must be recreated when it changes.
const [ multilineToolbar ] = useTriliumOptionBool("textNoteEditorMultilineToolbar");
+ // Rebuild triggers for the same reason, and there is no cheaper option for these: CKEditor bakes
+ // the transformation list at plugin init — `normalizeTransformations` runs once inside
+ // `_enableTransformationWatchers` — so unlike the settings read through a getter (link previews,
+ // clipboard image embedding) a live editor has nothing left to re-read.
+ const [ quoteReplacements ] = useTriliumOptionBool("textNoteQuoteReplacementsEnabled");
+ const [ punctuationReplacements ] = useTriliumOptionBool("textNotePunctuationReplacementsEnabled");
+ const [ mathReplacements ] = useTriliumOptionBool("textNoteMathReplacementsEnabled");
+ const [ symbolReplacements ] = useTriliumOptionBool("textNoteSymbolReplacementsEnabled");
+ // Which language a note with no `#language` of its own is written in, and so which quotes it
+ // gets. The UI locale it can fall back to is already covered by `uiLanguage` above.
+ const [ defaultContentLanguage ] = useTriliumOption("defaultContentLanguage");
const [ editor, setEditor ] = useState<CKTextEditor>();
const { parentComponent, ntxId, note } = useNoteContext();
@@ -274,7 +285,16 @@ export default function CKEditorWithWatchdog({ containerRef: externalContainerRe
};
// `templates` is intentionally excluded: snippet changes are pushed into the live editor by the
// effect below, so they must not trigger a full editor rebuild.
- }, [ contentLanguage, uiLanguage, isClassicEditor, multilineToolbar ]);
+ //
+ // The options below are not read in this effect — `buildConfig` goes to the options store
+ // itself — but they are listed so that changing one rebuilds the editor. The rebuild is what
+ // makes them apply to an already-open note; it costs the cursor position and undo history,
+ // which is acceptable for a change made deliberately over in the settings.
+ }, [
+ contentLanguage, uiLanguage, isClassicEditor, multilineToolbar,
+ quoteReplacements, punctuationReplacements, mathReplacements, symbolReplacements,
+ defaultContentLanguage
+ ]);
// Push snippet ("template") definitions into the live editor instead of rebuilding it. The premium
// Template plugin read its definitions once at init; TriliumSnippets keeps them in a live