No render performed after executing a custom run command

I’ve created a custom command with defined run function. This runs successfully when clicked but does not redraw so the icon is not indicated as active. If a built-in command is performed then the menu is redrawn and the custom command icon updated correctly.

Is it correct practice to call pm.signal("commandsChanged") in a custom run function or should the internal onclick or interaction handler perform the redraw automatically?

What kind of command is this? The menu is only redrawn when the selection or the document changes, at the moment.

It’s a UI oriented command that puts the editor into a full-screen mode and maintains the document scroll position.

Would it be workable to have your click handler update the menu widget? You can also call pm.mod.menuBar.updater.force(), but that’s somewhat clunky and likely to break in future versions. It might make sense to expose this as a documented method.

(But I’m not 100% happy about the way menu updates work in general – they are relatively costly, because everything needs to be redrawn and applicableness needs to be recomputed for every command, on every change. There might be value in optimizing things by having an intermediate value that computes applicability of the various menu elements, and then doing a more clever update based on changes in that value. Downside is that it’d add a bunch of complexity.)

Sure, at the moment I call pm.signal("commandsChanged") and seems to work flawlessly. Functionally how different is it to calling pm.mod.menuBar.updater.force()?

Perhaps the run function needs a cmd parameter similar to the render function, that way a a reference to the menu dom item can be attached to the cmd spec when render is called and later referenced in the run function with a simple classList.toggle.

It’ll do a bit more work (rebuilding the command groups, since it assumes the set of available commands changed), but that’s probably not significant in your case.

Have you tried adding a class to your menu icon and running .querySelector on pm.wrapper? It’s a bit hacky, but should give you access to the relevant DOM node.

Thanks, good point!