mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 11:56:01 +01:00
saving note detail
This commit is contained in:
@@ -3,6 +3,7 @@ import utils from "../services/utils.js";
|
||||
import protectedSessionHolder from "../services/protected_session_holder.js";
|
||||
import treeCache from "../services/tree_cache.js";
|
||||
import server from "../services/server.js";
|
||||
import SpacedUpdate from "../services/spaced_update.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="note-title-container">
|
||||
@@ -24,43 +25,6 @@ const TPL = `
|
||||
<input autocomplete="off" value="" class="note-title" tabindex="1">
|
||||
</div>`;
|
||||
|
||||
class SpacedUpdate {
|
||||
constructor(updater, updateInterval = 1000) {
|
||||
this.updater = updater;
|
||||
this.lastUpdated = Date.now();
|
||||
this.changed = false;
|
||||
this.updateInterval = updateInterval;
|
||||
}
|
||||
|
||||
scheduleUpdate() {
|
||||
this.changed = true;
|
||||
setTimeout(() => this.triggerUpdate())
|
||||
}
|
||||
|
||||
async updateNowIfNecessary() {
|
||||
if (this.changed) {
|
||||
this.changed = false;
|
||||
await this.updater();
|
||||
}
|
||||
}
|
||||
|
||||
triggerUpdate() {
|
||||
if (!this.changed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Date.now() - this.lastUpdated > this.updateInterval) {
|
||||
this.updater();
|
||||
this.lastUpdated = Date.now();
|
||||
this.changed = false;
|
||||
}
|
||||
else {
|
||||
// update not triggered but changes are still pending so we need to schedule another check
|
||||
this.scheduleUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default class NoteTitleWidget extends TabAwareWidget {
|
||||
constructor(appContext) {
|
||||
super(appContext);
|
||||
|
||||
Reference in New Issue
Block a user