Which part, the hotfixing part, or the keydown handler? To hotfix something like that, I have my plugin modify the class during plugin load, and then restore the original version on plugin unload. It’s better if it can be done on instances (like app or workspace) than on classes, because then you can just delete the wrapping function from the instance instead of having to save and restore the original.
As for the method, it’s basically:
onKeydown(e) {
if (e.key==="Escape") {
e.preventDefault();
this.hide();
}
}
For the hotfixing, it generally looks like this in a plugin onload:
const proto = Someclass.prototype, oldMethod = proto.someMethod;
this.register( () => proto.someMethod = oldMethod );
proto.someMethod = function(...) {
// possibly call `oldMethod.call(this, ...)` to invoke the original
}
This is not a terribly robust way of doing it; if I were going to make it compatible with other plugins possibly hotpatching the same method, I would wrap the new method in a function that would switch to calling the original method at exit time. That way, if another plugin hotpatched the same method, it would just end up calling the unpatched version if my plugin were unloaded.
But for the moment, I have very few hotfixes like this and as far as I know no other plugins are doing this sort of thing at the moment.