How to identify Editor instance in Editor gui_hooks

I’m specifically talking about editor_did_fire_typing_timer, editor_did_focus_field, and editor_did_unfocus_field.

I want to trigger a certain action, when the user types into editor fields. However the hooks only provide the note the editor has loaded, not the editor itself.

I was never able to actually use those hooks, because they don’t provide enough information. The editor could be from the browser, or the editcurrent window. Just providing the editor instance would already be enough.

I only see one “hack” possible: You take the note argument provided, and see which editor has it loaded. However what if both have them loaded?

Is there something I’m missing? Is there a way to infer which editor instance fired the hook?

2 Likes

Not the most beautiful solution, but

if hasattr(aqt.mw.app.activeWindow(), "editor"):
      editor = aqt.mw.app.activeWindow().editor
5 Likes

In the end, rather than overloading the hooks I mentioned in my opening post, I used the webview_did_receive_js_message hook, which will also be called everytime those hooks are called.