mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
fix(mermaid): lag during editing (closes #6443)
This commit is contained in:
parent
6021178b7d
commit
2072bd61d1
@ -51,6 +51,14 @@ export default class SpacedUpdate {
|
|||||||
this.lastUpdated = Date.now();
|
this.lastUpdated = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the update interval for the spaced update.
|
||||||
|
* @param interval The update interval in milliseconds.
|
||||||
|
*/
|
||||||
|
setUpdateInterval(interval: number) {
|
||||||
|
this.updateInterval = interval;
|
||||||
|
}
|
||||||
|
|
||||||
triggerUpdate() {
|
triggerUpdate() {
|
||||||
if (!this.changed) {
|
if (!this.changed) {
|
||||||
return;
|
return;
|
||||||
|
@ -130,7 +130,8 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.editorTypeWidget = new EditableCodeTypeWidget();
|
|
||||||
|
this.editorTypeWidget = new EditableCodeTypeWidget(true);
|
||||||
this.editorTypeWidget.updateBackgroundColor = () => {};
|
this.editorTypeWidget.updateBackgroundColor = () => {};
|
||||||
this.editorTypeWidget.isEnabled = () => true;
|
this.editorTypeWidget.isEnabled = () => true;
|
||||||
|
|
||||||
@ -146,6 +147,8 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
|
|||||||
doRender(): void {
|
doRender(): void {
|
||||||
this.$widget = $(TPL);
|
this.$widget = $(TPL);
|
||||||
|
|
||||||
|
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");
|
||||||
|
@ -28,6 +28,16 @@ const TPL = /*html*/`
|
|||||||
|
|
||||||
export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget {
|
export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget {
|
||||||
|
|
||||||
|
private debounceUpdate: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param debounceUpdate if true, the update will be debounced to prevent excessive updates. Especially useful if the editor is linked to a live preview.
|
||||||
|
*/
|
||||||
|
constructor(debounceUpdate: boolean = false) {
|
||||||
|
super();
|
||||||
|
this.debounceUpdate = debounceUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
static getType() {
|
static getType() {
|
||||||
return "editableCode";
|
return "editableCode";
|
||||||
}
|
}
|
||||||
@ -46,7 +56,13 @@ export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget {
|
|||||||
return {
|
return {
|
||||||
placeholder: t("editable_code.placeholder"),
|
placeholder: t("editable_code.placeholder"),
|
||||||
vimKeybindings: options.is("vimKeymapEnabled"),
|
vimKeybindings: options.is("vimKeymapEnabled"),
|
||||||
onContentChanged: () => this.spacedUpdate.scheduleUpdate(),
|
onContentChanged: () => {
|
||||||
|
if (this.debounceUpdate) {
|
||||||
|
this.spacedUpdate.resetUpdateTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.spacedUpdate.scheduleUpdate();
|
||||||
|
},
|
||||||
tabIndex: 300
|
tabIndex: 300
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user