chore(react/type_widget): react to line wrapping

This commit is contained in:
Elian Doran 2025-09-20 11:25:07 +03:00
parent f496caa92c
commit 6bcce08042
No known key found for this signature in database
2 changed files with 4 additions and 23 deletions

View File

@ -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} />
)

View File

@ -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"));
}
}
}