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();