From 3dbe44217bb904179c2cf13cdb84dfea807697b3 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Mon, 19 Jul 2021 07:21:13 +0200 Subject: [PATCH] Add a hook to execute after pasting in a field I expect to use it to ensure that images are resizable after they get pasted in a field --- qt/aqt/editor.py | 1 + qt/tools/genhooks_gui.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 052833748..1cfc433b6 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -954,6 +954,7 @@ $editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{ else: ext = "false" self.web.eval(f"pasteHTML({json.dumps(html)}, {json.dumps(internal)}, {ext});") + gui_hooks.editor_did_paste(self, html, internal, extended) def doDrop(self, html: str, internal: bool, extended: bool = False) -> None: def pasteIfField(ret: bool) -> None: diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index aebeb2587..a97ff21f7 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -843,6 +843,16 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) doc="""Allows changing the javascript commands to load note before executing it and do change in the QT editor.""", ), + Hook( + name="editor_did_paste", + args=[ + "editor: aqt.editor.Editor", + "html: str", + "internal: bool", + "extended: bool", + ], + doc="""Called after some data is pasted by python into an editor field.""", + ), # Tag ################### Hook(name="tag_editor_did_process_key", args=["tag_edit: TagEdit", "evt: QEvent"]),