diff --git a/main.js b/main.js index f55fa28..ede39d8 100644 --- a/main.js +++ b/main.js @@ -5,10 +5,27 @@ module.exports = class RibbonOrderLock extends Plugin { this.settings = Object.assign({ order: [] }, await this.loadData()); this.app.workspace.onLayoutReady(() => { + this.patchRibbon(); this.enforceOrder(); }); } + // hook the ribbon's own onChange so drags and hide/show toggles update + // our saved order automatically, same as Obsidian's native reorder does + patchRibbon() { + const ribbon = this.app.workspace.leftRibbon; + + const original = ribbon.onChange.bind(ribbon); + this.originalOnChange = original; + + ribbon.onChange = (save) => { + original(save); + if (save) { + this.recordOrder(ribbon); + } + }; + } + enforceOrder() { const ribbon = this.app.workspace.leftRibbon;