chore(code): reintroduce line wrapping

This commit is contained in:
Elian Doran 2025-05-11 12:07:54 +03:00
parent 9867cd83c4
commit 2628132350
No known key found for this signature in database
2 changed files with 7 additions and 0 deletions

View File

@ -1,3 +1,4 @@
import options from "../../services/options.js";
import TypeWidget from "./type_widget.js"; import TypeWidget from "./type_widget.js";
import CodeMirror, { type EditorConfig } from "@triliumnext/codemirror"; import CodeMirror, { type EditorConfig } from "@triliumnext/codemirror";
@ -26,6 +27,7 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
async #initEditor() { async #initEditor() {
this.codeEditor = new CodeMirror({ this.codeEditor = new CodeMirror({
parent: this.$editor[0], parent: this.$editor[0],
lineWrapping: options.is("codeLineWrapEnabled"),
...this.getExtraOpts() ...this.getExtraOpts()
}); });
} }

View File

@ -8,6 +8,7 @@ type ContentChangedListener = () => void;
export interface EditorConfig extends EditorViewConfig { export interface EditorConfig extends EditorViewConfig {
placeholder?: string; placeholder?: string;
lineWrapping?: boolean;
onContentChanged?: ContentChangedListener; onContentChanged?: ContentChangedListener;
} }
@ -37,6 +38,10 @@ export default class CodeMirror extends EditorView {
extensions.push(placeholder(config.placeholder)); extensions.push(placeholder(config.placeholder));
} }
if (config.lineWrapping) {
extensions.push(EditorView.lineWrapping);
}
if (config.onContentChanged) { if (config.onContentChanged) {
extensions.push(EditorView.updateListener.of((v) => this.#onDocumentUpdated(v))); extensions.push(EditorView.updateListener.of((v) => this.#onDocumentUpdated(v)));
} }