mirror of
https://github.com/jsmorabito/obsidian-commander.git
synced 2026-07-22 06:40:31 +00:00
fix: correct ribbon item property name and type WorkspaceRibbon.items
hidingViewer.tsx was already reading .title off left-ribbon items,
but leftRibbonManager.ts compared against a nonexistent .name
property. Combined with the self-compare bug fixed in 8c08808, that
means ribbon-item matching (used to recolor/remove a ribbon icon
when a command is edited or deleted) was effectively matching on
icon alone and never really checking the name/title at all - my
previous fix to i.name === pair.name would have made it match
nothing, since i.name doesn't exist on the real object. This fixes
it to compare i.title === pair.name, and adds a proper `items` type
to the WorkspaceRibbon module augmentation so this is now type-checked
instead of silently `any` behind @ts-expect-error.
Needs a manual check in Obsidian: add a left-ribbon command with a
custom color, confirm the ribbon icon picks up the color; delete a
left-ribbon command, confirm the correct icon (not another one
sharing its icon) is removed from the ribbon.
This commit is contained in:
parent
58e895e7e2
commit
2b58c0cbe0
3 changed files with 8 additions and 9 deletions
|
|
@ -36,10 +36,8 @@ export default class LeftRibbonManager extends CommandManagerBase {
|
|||
this.plugin.addRibbonIcon(pair.icon, pair.name, () =>
|
||||
this.plugin.app.commands.executeCommandById(pair.id)
|
||||
);
|
||||
// @ts-expect-error
|
||||
const nativeAction = this.plugin.app.workspace.leftRibbon.items.find(
|
||||
// @ts-expect-error
|
||||
(i) => i.icon === pair.icon && i.name === pair.name
|
||||
(i) => i.icon === pair.icon && i.title === pair.name
|
||||
);
|
||||
if (nativeAction) {
|
||||
nativeAction.buttonEl.style.color =
|
||||
|
|
@ -59,16 +57,13 @@ export default class LeftRibbonManager extends CommandManagerBase {
|
|||
this.plugin.settings.leftRibbon.remove(pair);
|
||||
await this.plugin.saveSettings();
|
||||
}
|
||||
// @ts-expect-error
|
||||
const nativeAction = this.plugin.app.workspace.leftRibbon.items.find(
|
||||
// @ts-expect-error
|
||||
(i) => i.icon === pair.icon && i.name === pair.name
|
||||
(i) => i.icon === pair.icon && i.title === pair.name
|
||||
);
|
||||
if (nativeAction) {
|
||||
nativeAction.buttonEl.remove();
|
||||
this.plugin.app.workspace.leftRibbon.items.remove(nativeAction);
|
||||
}
|
||||
// @ts-expect-error
|
||||
this.plugin.app.workspace.leftRibbon.items.remove(nativeAction);
|
||||
}
|
||||
|
||||
public reorder(): void {
|
||||
|
|
|
|||
|
|
@ -109,6 +109,11 @@ declare module "obsidian" {
|
|||
title: string;
|
||||
callback: () => void;
|
||||
}[];
|
||||
items: {
|
||||
icon: string;
|
||||
title: string;
|
||||
buttonEl: HTMLElement;
|
||||
}[];
|
||||
collapseButtonEl: HTMLElement;
|
||||
ribbonItemsEl: HTMLElement;
|
||||
addRibbonItemButton: (
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ export function LeftRibbonHider({
|
|||
const hiddenCommands = plugin.settings.hide.leftRibbon;
|
||||
useEffect(() => {
|
||||
setRibbonCommands(
|
||||
// @ts-expect-error
|
||||
plugin.app.workspace.leftRibbon.items.map((item) => ({
|
||||
name: item.title,
|
||||
icon: item.icon,
|
||||
|
|
|
|||
Loading…
Reference in a new issue