diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index 0b92b7459..fc8099551 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, 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, 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 9a06186a2..6fed6a889 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(null); const containerRef = useRef(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 8ff29fce2..8910da9a1 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 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 d9e94969f..5e7552894 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");