From 4de8def0bbb0f25d6af21447e80738942f4c435a Mon Sep 17 00:00:00 2001 From: bdeshi Date: Sat, 1 Aug 2026 20:27:10 +0600 Subject: [PATCH] use obsidian's builtin debounce --- main.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/main.js b/main.js index b8f6881..094e447 100644 --- a/main.js +++ b/main.js @@ -1,20 +1,12 @@ -const { Plugin } = require('obsidian'); - -// a bunch of ribbon icons can attach within milliseconds of each other on -// startup, so debounce instead of re-checking the order on every single one -function debounce(fn, wait) { - let timer = null; - return () => { - clearTimeout(timer); - timer = setTimeout(fn, wait); - }; -} +const { Plugin, debounce } = require('obsidian'); module.exports = class RibbonClasp extends Plugin { async onload() { this.settings = Object.assign({ order: [] }, await this.loadData()); this.enforcing = false; - this.debouncedEnforce = debounce(() => this.enforceOrder(), 200); + // icons can attach within milliseconds of each other on startup + // (resetTimer, or it fires 200ms after the first one instead of the last) + this.debouncedEnforce = debounce(() => this.enforceOrder(), 200, true); this.app.workspace.onLayoutReady(() => { this.patchRibbon();