mirror of
https://github.com/TriliumNext/Trilium.git
synced 2025-12-10 21:07:05 -06: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;
|
||||
}
|
||||
|
||||
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 codeEditorRef = useRef<VanillaCodeMirror>();
|
||||
|
||||
@ -41,6 +41,9 @@ export default function CodeMirror({ className, content, mime, editorRef: extern
|
||||
codeEditor?.clearHistory();
|
||||
}, [content]);
|
||||
|
||||
// React to line wrapping.
|
||||
useEffect(() => codeEditorRef.current?.setLineWrapping(!!lineWrapping), [ lineWrapping ]);
|
||||
|
||||
return (
|
||||
<pre ref={parentRef} className={className} />
|
||||
)
|
||||
|
||||
@ -53,11 +53,6 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
|
||||
// Do nothing by default.
|
||||
}
|
||||
|
||||
show() {
|
||||
this.$widget.show();
|
||||
this.updateBackgroundColor();
|
||||
}
|
||||
|
||||
focus() {
|
||||
this.codeEditor.focus();
|
||||
}
|
||||
@ -67,21 +62,4 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
|
||||
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