mirror of
https://github.com/jsmorabito/obsidian-commander.git
synced 2026-07-22 06:40:31 +00:00
Fix: Commander Ribbon Elements Reordering on Changes #137
This commit is contained in:
parent
9a0b731b06
commit
e822b9c7d2
2 changed files with 31 additions and 24 deletions
|
|
@ -32,21 +32,21 @@ export default class LeftRibbonManager extends CommandManagerBase {
|
|||
this.plugin.settings.leftRibbon.push(pair);
|
||||
await this.plugin.saveSettings();
|
||||
}
|
||||
if (isModeActive(pair.mode)) {
|
||||
this.plugin.addRibbonIcon(pair.icon, pair.name, () =>
|
||||
app.commands.executeCommandById(pair.id)
|
||||
);
|
||||
this.plugin.addRibbonIcon(pair.icon, pair.name, () =>
|
||||
app.commands.executeCommandById(pair.id)
|
||||
);
|
||||
// @ts-expect-error
|
||||
const nativeAction = app.workspace.leftRibbon.items.find((i, index) => {
|
||||
const pairId = `${this.plugin.manifest.id}:${pair.name}`;
|
||||
return i.id === pairId;
|
||||
});
|
||||
if (nativeAction) {
|
||||
nativeAction.hidden = !isModeActive(pair.mode);
|
||||
// @ts-expect-error
|
||||
const nativeAction = app.workspace.leftRibbon.items.find(
|
||||
// @ts-expect-error
|
||||
(i) => i.icon === pair.icon && i.name === i.name
|
||||
);
|
||||
if (nativeAction) {
|
||||
nativeAction.buttonEl.style.color =
|
||||
pair.color === "#000000" || pair.color === undefined
|
||||
? "inherit"
|
||||
: pair.color;
|
||||
}
|
||||
nativeAction.buttonEl.style.color =
|
||||
pair.color === "#000000" || pair.color === undefined
|
||||
? "inherit"
|
||||
: pair.color;
|
||||
this.plugin.register(() => this.removeCommand(pair, false));
|
||||
}
|
||||
}
|
||||
|
|
@ -60,10 +60,10 @@ export default class LeftRibbonManager extends CommandManagerBase {
|
|||
await this.plugin.saveSettings();
|
||||
}
|
||||
// @ts-expect-error
|
||||
const nativeAction = app.workspace.leftRibbon.items.find(
|
||||
// @ts-expect-error
|
||||
(i) => i.icon === pair.icon && i.name === i.name
|
||||
);
|
||||
const nativeAction = app.workspace.leftRibbon.items.find((i, index) => {
|
||||
const pairId = `${this.plugin.manifest.id}:${pair.name}`;
|
||||
return i.id === pairId;
|
||||
});
|
||||
if (nativeAction) {
|
||||
nativeAction.buttonEl.remove();
|
||||
}
|
||||
|
|
@ -78,4 +78,11 @@ export default class LeftRibbonManager extends CommandManagerBase {
|
|||
this.addCommand(pair, false);
|
||||
});
|
||||
}
|
||||
|
||||
public update(): void {
|
||||
this.plugin.settings.leftRibbon.forEach((pair) => {
|
||||
this.addCommand(pair, false);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,9 +71,10 @@ export default function CommandViewer({
|
|||
handleRename={async (
|
||||
name
|
||||
): Promise<void> => {
|
||||
cmd.name = name;
|
||||
manager.removeCommand(cmd);
|
||||
await plugin.saveSettings();
|
||||
manager.reorder();
|
||||
cmd.name = name;
|
||||
manager.addCommand(cmd);
|
||||
this.forceUpdate();
|
||||
}}
|
||||
handleNewIcon={async (): Promise<void> => {
|
||||
|
|
@ -84,7 +85,7 @@ export default function CommandViewer({
|
|||
if (newIcon && newIcon !== cmd.icon) {
|
||||
cmd.icon = newIcon;
|
||||
await plugin.saveSettings();
|
||||
manager.reorder();
|
||||
manager.update();
|
||||
this.forceUpdate();
|
||||
}
|
||||
dispatchEvent(
|
||||
|
|
@ -109,7 +110,7 @@ export default function CommandViewer({
|
|||
cmd.mode =
|
||||
mode || modes[currentIdx + 1];
|
||||
await plugin.saveSettings();
|
||||
manager.reorder();
|
||||
manager.update();
|
||||
this.forceUpdate();
|
||||
}}
|
||||
handleColorChange={async (
|
||||
|
|
@ -117,7 +118,7 @@ export default function CommandViewer({
|
|||
): Promise<void> => {
|
||||
cmd.color = color;
|
||||
await plugin.saveSettings();
|
||||
manager.reorder();
|
||||
manager.update();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
|
@ -146,7 +147,6 @@ export default function CommandViewer({
|
|||
onClick={async (): Promise<void> => {
|
||||
const pair = await chooseNewCommand(plugin);
|
||||
await manager.addCommand(pair);
|
||||
manager.reorder();
|
||||
this.forceUpdate();
|
||||
}}
|
||||
>
|
||||
|
|
|
|||
Loading…
Reference in a new issue