Skip to content

Build your personal knowledge base with Trilium Notes

feat(mermaid): disable line wrapping by default

Elian Doran91dca2df35be
diff --git a/src/public/app/types.d.ts b/src/public/app/types.d.ts
index 9dd85192b4..7c0175d0a7 100644
--- a/src/public/app/types.d.ts
+++ b/src/public/app/types.d.ts
@@ -186,20 +186,28 @@ declare global {
attach(editor: TextEditor);
};
+ interface CodeMirrorOpts {
+ value: string;
+ viewportMargin: number;
+ indentUnit: number;
+ matchBrackets: boolean;
+ matchTags: { bothTags: boolean };
+ highlightSelectionMatches: {
+ showToken: boolean;
+ annotateScrollbar: boolean;
+ };
+ lineNumbers: boolean;
+ lineWrapping: boolean;
+ keyMap: "vim" | "default";
+ lint: boolean;
+ gutters: string[];
+ tabindex: number;
+ dragDrop: boolean;
+ placeholder: string;
+ }
+
var CodeMirror: {
- (el: HTMLElement, opts: {
- value: string;
- viewportMargin: number;
- indentUnit: number;
- matchBrackets: boolean;
- matchTags: { bothTags: boolean };
- highlightSelectionMatches: {
- showToken: boolean;
- annotateScrollbar: boolean;
- };
- lineNumbers: boolean;
- lineWrapping: boolean;
- }): CodeMirrorInstance;
+ (el: HTMLElement, opts: CodeMirrorOpts): CodeMirrorInstance;
keyMap: {
default: Record<string, string>;
};
diff --git a/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts b/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts
index 532951d5c1..69bc38bd7f 100644
--- a/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts
+++ b/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts
@@ -64,7 +64,7 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
*
* @returns the extra options to be passed to the CodeMirror constructor.
*/
- getExtraOpts() {
+ getExtraOpts(): Partial<CodeMirrorOpts> {
return {};
}
diff --git a/src/public/app/widgets/type_widgets/abstract_split_type_widget.ts b/src/public/app/widgets/type_widgets/abstract_split_type_widget.ts
index e313ba8a78..aad7d89eec 100644
--- a/src/public/app/widgets/type_widgets/abstract_split_type_widget.ts
+++ b/src/public/app/widgets/type_widgets/abstract_split_type_widget.ts
@@ -92,6 +92,7 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
super();
this.editorTypeWidget = new EditableCodeTypeWidget();
this.editorTypeWidget.isEnabled = () => true;
+ this.editorTypeWidget.getExtraOpts = this.buildEditorExtraOptions;
}
doRender(): void {
@@ -139,13 +140,20 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
/**
* Called upon when the split between the preview and content pane is initialized. Can be used to add additional listeners if needed.
- *
- * @returns the additional split options.
*/
buildSplitExtraOptions(): Split.Options {
return {};
}
+ /**
+ * Called upon when the code editor is being initialized. Can be used to add additional options to the editor.
+ */
+ buildEditorExtraOptions(): Partial<CodeMirrorOpts> {
+ return {
+ lineWrapping: false
+ };
+ }
+
setError(message: string | null | undefined) {
this.$errorContainer.toggleClass("hidden-ext", !message);
this.$preview.toggleClass("on-error", !!message);
diff --git a/src/public/app/widgets/type_widgets/editable_code.ts b/src/public/app/widgets/type_widgets/editable_code.ts
index 06c3ece64a..6b6893736e 100644
--- a/src/public/app/widgets/type_widgets/editable_code.ts
+++ b/src/public/app/widgets/type_widgets/editable_code.ts
@@ -38,7 +38,7 @@ export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget {
super.doRender();
}
- getExtraOpts() {
+ getExtraOpts(): Partial<CodeMirrorOpts> {
return {
keyMap: options.is("vimKeymapEnabled") ? "vim" : "default",
lint: true,