From 8c088088231fef790bed9f0168855395bc03b057 Mon Sep 17 00:00:00 2001 From: johnny1093 <46250921+jsmorabito@users.noreply.github.com> Date: Sat, 11 Jul 2026 09:26:19 -0400 Subject: [PATCH] fix: correct ribbon item matching and stray global app references - leftRibbonManager was comparing i.name === i.name (always true) instead of i.name === pair.name when locating a ribbon item to recolor/remove, so items sharing an icon with a different-named command could be matched incorrectly. Now compares against pair.name. - Replace two stray references to the global `app` with the plugin's own `app` reference (this.plugin.app / plugin.app), consistent with the rest of the codebase. - Use Object.prototype.hasOwnProperty.call() instead of calling hasOwnProperty directly on values that may not inherit from Object.prototype. - Import Command/PluginManifest in types.ts so the Obsidian module augmentation resolves them instead of relying on ambient globals. - Drop a leftover console.log of an expected/benign cancellation error in the "Add command" menu action. --- src/manager/commands/leftRibbonManager.ts | 6 +++--- src/manager/commands/menuManager.ts | 3 +-- src/types.ts | 1 + src/ui/components/commandComponent.tsx | 4 ++-- src/ui/components/hidingViewer.tsx | 2 +- src/util.tsx | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/manager/commands/leftRibbonManager.ts b/src/manager/commands/leftRibbonManager.ts index 26e1990..8de4122 100644 --- a/src/manager/commands/leftRibbonManager.ts +++ b/src/manager/commands/leftRibbonManager.ts @@ -39,7 +39,7 @@ export default class LeftRibbonManager extends CommandManagerBase { // @ts-expect-error const nativeAction = this.plugin.app.workspace.leftRibbon.items.find( // @ts-expect-error - (i) => i.icon === pair.icon && i.name === i.name + (i) => i.icon === pair.icon && i.name === pair.name ); if (nativeAction) { nativeAction.buttonEl.style.color = @@ -62,13 +62,13 @@ export default class LeftRibbonManager extends CommandManagerBase { // @ts-expect-error const nativeAction = this.plugin.app.workspace.leftRibbon.items.find( // @ts-expect-error - (i) => i.icon === pair.icon && i.name === i.name + (i) => i.icon === pair.icon && i.name === pair.name ); if (nativeAction) { nativeAction.buttonEl.remove(); } // @ts-expect-error - app.workspace.leftRibbon.items.remove(nativeAction); + this.plugin.app.workspace.leftRibbon.items.remove(nativeAction); } public reorder(): void { diff --git a/src/manager/commands/menuManager.ts b/src/manager/commands/menuManager.ts index 690ad23..0178abd 100644 --- a/src/manager/commands/menuManager.ts +++ b/src/manager/commands/menuManager.ts @@ -163,8 +163,7 @@ abstract class Base extends CommandManagerBase { commandList.push(pair); await plugin.saveSettings(); } catch (error) { - //Do some proper handling here - console.log(error); + // User cancelled command/icon selection, nothing to do } }); }); diff --git a/src/types.ts b/src/types.ts index 2130ff5..703ed7b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ import { h } from "preact"; +import { Command, PluginManifest } from "obsidian"; export enum Action { COMMAND, diff --git a/src/ui/components/commandComponent.tsx b/src/ui/components/commandComponent.tsx index 39a11d5..3b2c1f0 100644 --- a/src/ui/components/commandComponent.tsx +++ b/src/ui/components/commandComponent.tsx @@ -100,8 +100,8 @@ export default function CommandComponent({ const owningPlugin = plugin.app.plugins.manifests[owningPluginID!]; const isInternal = !owningPlugin; const isChecked = - cmd.hasOwnProperty("checkCallback") || - cmd.hasOwnProperty("editorCheckCallback"); + Object.prototype.hasOwnProperty.call(cmd, "checkCallback") || + Object.prototype.hasOwnProperty.call(cmd, "editorCheckCallback"); const modeIcon = getModeIcon(pair.mode); const modeName = pair.mode.match(/desktop|mobile|any/) diff --git a/src/ui/components/hidingViewer.tsx b/src/ui/components/hidingViewer.tsx index 783e04b..c4d552c 100644 --- a/src/ui/components/hidingViewer.tsx +++ b/src/ui/components/hidingViewer.tsx @@ -19,7 +19,7 @@ export function LeftRibbonHider({ useEffect(() => { setRibbonCommands( // @ts-expect-error - app.workspace.leftRibbon.items.map((item) => ({ + plugin.app.workspace.leftRibbon.items.map((item) => ({ name: item.title, icon: item.icon, })) diff --git a/src/util.tsx b/src/util.tsx index 95ea385..3b410e7 100644 --- a/src/util.tsx +++ b/src/util.tsx @@ -24,7 +24,7 @@ export async function chooseNewCommand( const command = await new AddCommandModal(plugin).awaitSelection(); let icon; - if (!command.hasOwnProperty("icon")) { + if (!Object.prototype.hasOwnProperty.call(command, "icon")) { icon = await new ChooseIconModal(plugin).awaitSelection(); }