How to override 'save', 'save as' and 'undo' for image editor?


#1

Hi guys
I created an experimental package that allows drawing on images:

Undoing and saving already works but not via default Atom functionality.
Now I want to override the ‘save’ and ‘undo’ functionality for only this drawing editor.

I saw that it’s possible to override the save command for all editors, but I’d prefer not to override these commands in general:

Thanks for any hints :wink:


#2

If you can override them for all editors then you can just check to see if it is yours and if not, continue the save/undo for the other.


#3

You can have your editor element accept core:save and core:undo and then do nothing with them if the focused element is your editor. See here for more information:

https://atom.io/docs/latest/behind-atom-keymaps-in-depth#overloading-key-bindings


#4

I’m now listening to all ‘core:undo’, ‘core:save’, ‘core:save-as’ events and dispatch them internally. And it works!

(Altough implementing was a bit shaky: don’t correctly dispatch ‘save’ and you cannot change your code anymore ;))