mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 17:08:58 +01:00
chore(react/type_widget): bring back update interval
This commit is contained in:
parent
b19da81572
commit
6dd939df14
@ -75,11 +75,12 @@ export function useSpacedUpdate(callback: () => void | Promise<void>, interval =
|
|||||||
return spacedUpdateRef.current;
|
return spacedUpdateRef.current;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useEditorSpacedUpdate({ note, getData, onContentChange, dataSaved }: {
|
export function useEditorSpacedUpdate({ note, getData, onContentChange, dataSaved, updateInterval }: {
|
||||||
note: FNote,
|
note: FNote,
|
||||||
getData: () => Promise<object | undefined> | object | undefined,
|
getData: () => Promise<object | undefined> | object | undefined,
|
||||||
onContentChange: (newContent: string) => void,
|
onContentChange: (newContent: string) => void,
|
||||||
dataSaved?: () => void
|
dataSaved?: () => void,
|
||||||
|
updateInterval?: number;
|
||||||
}) {
|
}) {
|
||||||
const parentComponent = useContext(ParentComponent);
|
const parentComponent = useContext(ParentComponent);
|
||||||
const blob = useNoteBlob(note, parentComponent?.componentId);
|
const blob = useNoteBlob(note, parentComponent?.componentId);
|
||||||
@ -105,6 +106,9 @@ export function useEditorSpacedUpdate({ note, getData, onContentChange, dataSave
|
|||||||
spacedUpdate.allowUpdateWithoutChange(() => onContentChange(blob.content));
|
spacedUpdate.allowUpdateWithoutChange(() => onContentChange(blob.content));
|
||||||
}, [ blob ]);
|
}, [ blob ]);
|
||||||
|
|
||||||
|
// React to update interval changes.
|
||||||
|
useEffect(() => spacedUpdate.setUpdateInterval(updateInterval), [ updateInterval ]);
|
||||||
|
|
||||||
return spacedUpdate;
|
return spacedUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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.
|
// if true, the update will be debounced to prevent excessive updates. Especially useful if the editor is linked to a live preview.
|
||||||
debounceUpdate?: boolean;
|
debounceUpdate?: boolean;
|
||||||
lineWrapping?: boolean;
|
lineWrapping?: boolean;
|
||||||
|
updateInterval?: number;
|
||||||
}) {
|
}) {
|
||||||
const editorRef = useRef<VanillaCodeMirror>(null);
|
const editorRef = useRef<VanillaCodeMirror>(null);
|
||||||
const containerRef = useRef<HTMLPreElement>(null);
|
const containerRef = useRef<HTMLPreElement>(null);
|
||||||
@ -52,7 +53,8 @@ export function EditableCode({ note, ntxId, debounceUpdate, parentComponent, ...
|
|||||||
codeEditor.setText(content ?? "");
|
codeEditor.setText(content ?? "");
|
||||||
codeEditor.setMimeType(note.mime);
|
codeEditor.setMimeType(note.mime);
|
||||||
codeEditor.clearHistory();
|
codeEditor.clearHistory();
|
||||||
}
|
},
|
||||||
|
updateInterval
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set up keyboard shortcuts.
|
// Set up keyboard shortcuts.
|
||||||
|
|||||||
@ -33,6 +33,7 @@ export default function SplitEditor({ note, error, splitOptions, ...editorProps
|
|||||||
<EditableCode
|
<EditableCode
|
||||||
note={note}
|
note={note}
|
||||||
lineWrapping={false}
|
lineWrapping={false}
|
||||||
|
updateInterval={750} debounceUpdate
|
||||||
{...editorProps}
|
{...editorProps}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -25,7 +25,6 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.editorTypeWidget = new EditableCodeTypeWidget(true);
|
|
||||||
this.editorTypeWidget.updateBackgroundColor = () => {};
|
this.editorTypeWidget.updateBackgroundColor = () => {};
|
||||||
this.editorTypeWidget.isEnabled = () => true;
|
this.editorTypeWidget.isEnabled = () => true;
|
||||||
|
|
||||||
@ -39,8 +38,6 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doRender(): void {
|
doRender(): void {
|
||||||
this.spacedUpdate.setUpdateInterval(750);
|
|
||||||
|
|
||||||
// Preview pane
|
// Preview pane
|
||||||
this.$previewCol = this.$widget.find(".note-detail-split-preview-col");
|
this.$previewCol = this.$widget.find(".note-detail-split-preview-col");
|
||||||
this.$preview = this.$widget.find(".note-detail-split-preview");
|
this.$preview = this.$widget.find(".note-detail-split-preview");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user