Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widget): bring back update interval

Elian Doran6dd939df1468
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx
index 0b92b7459c..fc80995514 100644
--- a/apps/client/src/widgets/react/hooks.tsx
+++ b/apps/client/src/widgets/react/hooks.tsx
@@ -75,11 +75,12 @@ export function useSpacedUpdate(callback: () => void | Promise<void>, interval =
return spacedUpdateRef.current;
}
-export function useEditorSpacedUpdate({ note, getData, onContentChange, dataSaved }: {
+export function useEditorSpacedUpdate({ note, getData, onContentChange, dataSaved, updateInterval }: {
note: FNote,
getData: () => Promise<object | undefined> | object | undefined,
onContentChange: (newContent: string) => void,
- dataSaved?: () => void
+ dataSaved?: () => void,
+ updateInterval?: number;
}) {
const parentComponent = useContext(ParentComponent);
const blob = useNoteBlob(note, parentComponent?.componentId);
@@ -105,6 +106,9 @@ export function useEditorSpacedUpdate({ note, getData, onContentChange, dataSave
spacedUpdate.allowUpdateWithoutChange(() => onContentChange(blob.content));
}, [ blob ]);
+ // React to update interval changes.
+ useEffect(() => spacedUpdate.setUpdateInterval(updateInterval), [ updateInterval ]);
+
return spacedUpdate;
}
diff --git a/apps/client/src/widgets/type_widgets/code/Code.tsx b/apps/client/src/widgets/type_widgets/code/Code.tsx
index 9a06186a24..6fed6a8890 100644
--- a/apps/client/src/widgets/type_widgets/code/Code.tsx
+++ b/apps/client/src/widgets/type_widgets/code/Code.tsx
@@ -35,10 +35,11 @@ export function ReadOnlyCode({ note, viewScope, ntxId, parentComponent }: TypeWi
)
}
-export function EditableCode({ note, ntxId, debounceUpdate, parentComponent, ...editorProps }: TypeWidgetProps & {
+export function EditableCode({ note, ntxId, debounceUpdate, parentComponent, updateInterval, ...editorProps }: TypeWidgetProps & {
// if true, the update will be debounced to prevent excessive updates. Especially useful if the editor is linked to a live preview.
debounceUpdate?: boolean;
lineWrapping?: boolean;
+ updateInterval?: number;
}) {
const editorRef = useRef<VanillaCodeMirror>(null);
const containerRef = useRef<HTMLPreElement>(null);
@@ -52,7 +53,8 @@ export function EditableCode({ note, ntxId, debounceUpdate, parentComponent, ...
codeEditor.setText(content ?? "");
codeEditor.setMimeType(note.mime);
codeEditor.clearHistory();
- }
+ },
+ updateInterval
});
// Set up keyboard shortcuts.
diff --git a/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx b/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx
index 8ff29fce29..8910da9a19 100644
--- a/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx
+++ b/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx
@@ -33,6 +33,7 @@ export default function SplitEditor({ note, error, splitOptions, ...editorProps
<EditableCode
note={note}
lineWrapping={false}
+ updateInterval={750} debounceUpdate
{...editorProps}
/>
</div>
diff --git a/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts b/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts
index d9e94969fd..5e7552894e 100644
--- a/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts
+++ b/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts
@@ -25,7 +25,6 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
constructor() {
super();
- this.editorTypeWidget = new EditableCodeTypeWidget(true);
this.editorTypeWidget.updateBackgroundColor = () => {};
this.editorTypeWidget.isEnabled = () => true;
@@ -39,8 +38,6 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
}
doRender(): void {
- this.spacedUpdate.setUpdateInterval(750);
-
// Preview pane
this.$previewCol = this.$widget.find(".note-detail-split-preview-col");
this.$preview = this.$widget.find(".note-detail-split-preview");