mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
Added debouncing
This commit is contained in:
9
main.ts
9
main.ts
@@ -1,4 +1,4 @@
|
||||
import { TFile, Plugin, MarkdownView } from 'obsidian';
|
||||
import { TFile, Plugin, MarkdownView, debounce, Debouncer } from 'obsidian';
|
||||
|
||||
interface WordCount {
|
||||
initial: number;
|
||||
@@ -20,6 +20,7 @@ export default class DailyStats extends Plugin {
|
||||
statusBarEl: HTMLElement;
|
||||
currentWordCount: number;
|
||||
today: string;
|
||||
debouncedUpdate: Debouncer<[contents: string, filepath: string]>;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
@@ -32,6 +33,10 @@ export default class DailyStats extends Plugin {
|
||||
this.currentWordCount = 0;
|
||||
}
|
||||
|
||||
this.debouncedUpdate = debounce((contents: string, filepath: string) => {
|
||||
this.updateWordCount(contents, filepath);
|
||||
}, 400, false);
|
||||
|
||||
this.registerEvent(
|
||||
this.app.workspace.on("quit", this.onunload.bind(this))
|
||||
);
|
||||
@@ -58,7 +63,7 @@ export default class DailyStats extends Plugin {
|
||||
|
||||
onQuickPreview(file: TFile, contents: string) {
|
||||
if (this.app.workspace.getActiveViewOfType(MarkdownView)) {
|
||||
this.updateWordCount(contents, file.path);
|
||||
this.debouncedUpdate(contents, file.path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user