our own reorder was tripping the hook and saving over itself

This commit is contained in:
bdeshi committed 2026-07-05 00:53:31 +06:00
1 parent 7fe98170ba
commit dc3c5428e2
1 file changed
+8 -2
+8 -2
View File
@@ -13,6 +13,7 @@ function debounce(fn, wait) {
module.exports = class RibbonOrderLock extends Plugin { module.exports = class RibbonOrderLock extends Plugin {
async onload() { async onload() {
this.settings = Object.assign({ order: [] }, await this.loadData()); this.settings = Object.assign({ order: [] }, await this.loadData());
this.enforcing = false;
this.debouncedEnforce = debounce(() => this.enforceOrder(), 200); this.debouncedEnforce = debounce(() => this.enforceOrder(), 200);
this.app.workspace.onLayoutReady(() => { this.app.workspace.onLayoutReady(() => {
@@ -40,7 +41,7 @@ module.exports = class RibbonOrderLock extends Plugin {
ribbon.onChange = (save) => { ribbon.onChange = (save) => {
original(save); original(save);
if (save) { if (save && !this.enforcing) {
this.recordOrder(ribbon); this.recordOrder(ribbon);
} }
}; };
@@ -68,7 +69,12 @@ module.exports = class RibbonOrderLock extends Plugin {
if (changed) { if (changed) {
ribbon.items.length = 0; ribbon.items.length = 0;
ribbon.items.push(...sorted); ribbon.items.push(...sorted);
ribbon.onChange(true); this.enforcing = true;
try {
ribbon.onChange(true);
} finally {
this.enforcing = false;
}
} }
this.mergeNewItems(ribbon); this.mergeNewItems(ribbon);