mirror of
https://github.com/zadam/trilium.git
synced 2026-01-07 15:14:24 +01:00
chore(react/type_widget): react to line wrapping
This commit is contained in:
parent
f496caa92c
commit
6bcce08042
@ -12,7 +12,7 @@ export interface CodeMirrorProps extends Omit<EditorConfig, "parent"> {
|
|||||||
onInitialized?: () => void;
|
onInitialized?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CodeMirror({ className, content, mime, editorRef: externalEditorRef, containerRef: externalContainerRef, onInitialized, ...extraOpts }: CodeMirrorProps) {
|
export default function CodeMirror({ className, content, mime, editorRef: externalEditorRef, containerRef: externalContainerRef, onInitialized, lineWrapping, ...extraOpts }: CodeMirrorProps) {
|
||||||
const parentRef = useSyncedRef(externalContainerRef);
|
const parentRef = useSyncedRef(externalContainerRef);
|
||||||
const codeEditorRef = useRef<VanillaCodeMirror>();
|
const codeEditorRef = useRef<VanillaCodeMirror>();
|
||||||
|
|
||||||
@ -41,6 +41,9 @@ export default function CodeMirror({ className, content, mime, editorRef: extern
|
|||||||
codeEditor?.clearHistory();
|
codeEditor?.clearHistory();
|
||||||
}, [content]);
|
}, [content]);
|
||||||
|
|
||||||
|
// React to line wrapping.
|
||||||
|
useEffect(() => codeEditorRef.current?.setLineWrapping(!!lineWrapping), [ lineWrapping ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<pre ref={parentRef} className={className} />
|
<pre ref={parentRef} className={className} />
|
||||||
)
|
)
|
||||||
|
|||||||
@ -53,11 +53,6 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
|
|||||||
// Do nothing by default.
|
// Do nothing by default.
|
||||||
}
|
}
|
||||||
|
|
||||||
show() {
|
|
||||||
this.$widget.show();
|
|
||||||
this.updateBackgroundColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
focus() {
|
focus() {
|
||||||
this.codeEditor.focus();
|
this.codeEditor.focus();
|
||||||
}
|
}
|
||||||
@ -67,21 +62,4 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
|
|||||||
this.codeEditor.focus();
|
this.codeEditor.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
|
||||||
if (loadResults.isOptionReloaded("codeNoteTheme")) {
|
|
||||||
const themeId = options.get("codeNoteTheme");
|
|
||||||
if (themeId?.startsWith(DEFAULT_PREFIX)) {
|
|
||||||
const theme = getThemeById(themeId.substring(DEFAULT_PREFIX.length));
|
|
||||||
if (theme) {
|
|
||||||
await this.codeEditor.setTheme(theme);
|
|
||||||
}
|
|
||||||
this.updateBackgroundColor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loadResults.isOptionReloaded("codeLineWrapEnabled")) {
|
|
||||||
this.codeEditor.setLineWrapping(options.is("codeLineWrapEnabled"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user