Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widget): bring back scroll to end

Elian Doran6ef468adc49c
diff --git a/apps/client/src/widgets/note_detail.ts.bak b/apps/client/src/widgets/note_detail.ts.bak
index 8b66102013..b85c7263d4 100644
--- a/apps/client/src/widgets/note_detail.ts.bak
+++ b/apps/client/src/widgets/note_detail.ts.bak
@@ -149,20 +149,6 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
widget.focus();
}
- async scrollToEndEvent({ ntxId }: EventData<"scrollToEnd">) {
- if (this.noteContext?.ntxId !== ntxId) {
- return;
- }
-
- await this.refresh();
- const widget = this.getTypeWidget();
- await widget.initialized;
-
- if (widget.scrollToEnd) {
- widget.scrollToEnd();
- }
- }
-
async beforeNoteSwitchEvent({ noteContext }: EventData<"beforeNoteSwitch">) {
if (this.isNoteContext(noteContext.ntxId)) {
await this.spacedUpdate.updateNowIfNecessary();
diff --git a/apps/client/src/widgets/type_widgets/code/Code.tsx b/apps/client/src/widgets/type_widgets/code/Code.tsx
index e78d869488..731141f4a8 100644
--- a/apps/client/src/widgets/type_widgets/code/Code.tsx
+++ b/apps/client/src/widgets/type_widgets/code/Code.tsx
@@ -131,6 +131,13 @@ function CodeEditor({ note, parentComponent, ntxId, containerRef: externalContai
resolve(refToJQuerySelector(containerRef));
});
+ useTriliumEvent("scrollToEnd", () => {
+ const editor = codeEditorRef.current;
+ if (!editor) return;
+ editor.scrollToEnd();
+ editor.focus();
+ });
+
return <CodeMirror
{...editorProps}
editorRef={codeEditorRef}
diff --git a/apps/client/src/widgets/type_widgets_old/abstract_code_type_widget.ts b/apps/client/src/widgets/type_widgets_old/abstract_code_type_widget.ts
index 0ea7d1f672..ede647ff7b 100644
--- a/apps/client/src/widgets/type_widgets_old/abstract_code_type_widget.ts
+++ b/apps/client/src/widgets/type_widgets_old/abstract_code_type_widget.ts
@@ -57,9 +57,4 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
this.codeEditor.focus();
}
- scrollToEnd() {
- this.codeEditor.scrollToEnd();
- this.codeEditor.focus();
- }
-
}