fix: macro icons now display correctly in all UI contexts

Set icon directly on addCommand so it appears in the command palette,
status bar, and mobile toolbar. Also fixes removeCommand referencing
bare `app` instead of `plugin.app`, and replaces Array.remove() during
forEach iteration (mutation hazard) with a filter in injectIcons.

Fixes #149 (cherry-picked from PR by Anton/Lyqed)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
John Morabito 2026-06-13 11:37:39 -04:00
parent 13c5c1e1b2
commit b4ae810c84

View file

@ -144,16 +144,17 @@ export function updateMacroCommands(plugin: CommanderPlugin): void {
);
for (const command of oldCommands) {
//@ts-ignore
app.commands.removeCommand(command);
plugin.app.commands.removeCommand(command);
}
const macros = plugin.settings.macros;
for (const [idx, macro] of Object.entries(macros)) {
for (const [idx, macro] of macros.entries()) {
plugin.addCommand({
id: `macro-${idx}`,
name: macro.name,
icon: macro.icon,
callback: () => {
plugin.executeMacro(parseInt(idx));
plugin.executeMacro(Number(idx));
},
});
}
@ -195,7 +196,7 @@ export function injectIcons(
if (command) {
command.icon = mapped.iconID;
} else {
settings.mappedIcons.remove(mapped);
settings.mappedIcons = settings.mappedIcons.filter(m => m !== mapped);
}
});
}