Skip to content

Build your personal knowledge base with Trilium Notes

chore(code): reintroduce some commented-out behaviours

Elian Doranbedbc9373c97
diff --git a/apps/client/src/widgets/type_widgets/abstract_code_type_widget.ts b/apps/client/src/widgets/type_widgets/abstract_code_type_widget.ts
index c75d857477..a2210081b2 100644
--- a/apps/client/src/widgets/type_widgets/abstract_code_type_widget.ts
+++ b/apps/client/src/widgets/type_widgets/abstract_code_type_widget.ts
@@ -80,28 +80,22 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
show() {
this.$widget.show();
-
- // if (this.codeEditor) {
- // // show can be called before render
- // this.codeEditor.refresh();
- // }
}
focus() {
- this.$editor.focus();
this.codeEditor.focus();
}
scrollToEnd() {
- // this.codeEditor.setCursor(this.codeEditor.lineCount(), 0);
- // this.codeEditor.focus();
+ this.codeEditor.scrollToEnd();
+ this.codeEditor.focus();
}
cleanup() {
if (this.codeEditor) {
- // this.spacedUpdate.allowUpdateWithoutChange(() => {
- // this.codeEditor.setValue("");
- // });
+ this.spacedUpdate.allowUpdateWithoutChange(() => {
+ this.codeEditor.setText("");
+ });
}
}
diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.ts
index 24a093caec..5661b4fc6a 100644
--- a/packages/codemirror/src/index.ts
+++ b/packages/codemirror/src/index.ts
@@ -1,7 +1,7 @@
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
import { EditorView, highlightActiveLine, keymap, lineNumbers, placeholder, ViewUpdate, type EditorViewConfig } from "@codemirror/view";
import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting, indentUnit, bracketMatching, foldGutter } from "@codemirror/language";
-import { Compartment, EditorState, type Extension } from "@codemirror/state";
+import { Compartment, EditorSelection, EditorState, type Extension } from "@codemirror/state";
import { highlightSelectionMatches } from "@codemirror/search";
import { vim } from "@replit/codemirror-vim";
import byMimeType from "./syntax_highlighting.js";
@@ -137,6 +137,15 @@ export default class CodeMirror extends EditorView {
});
}
+ scrollToEnd() {
+ const endPos = this.state.doc.length;
+ this.dispatch({
+ selection: EditorSelection.cursor(endPos),
+ effects: EditorView.scrollIntoView(endPos, { y: "end" }),
+ scrollIntoView: true
+ });
+ }
+
async setMimeType(mime: string) {
let newExtension: Extension[] = [];