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
This commit is contained in:
Arthur Milchior 2021-07-19 07:21:13 +02:00
parent bbddc79da4
commit 3dbe44217b
2 changed files with 11 additions and 0 deletions

View file

@ -954,6 +954,7 @@ $editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{
else: else:
ext = "false" ext = "false"
self.web.eval(f"pasteHTML({json.dumps(html)}, {json.dumps(internal)}, {ext});") 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 doDrop(self, html: str, internal: bool, extended: bool = False) -> None:
def pasteIfField(ret: bool) -> None: def pasteIfField(ret: bool) -> None:

View file

@ -843,6 +843,16 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
doc="""Allows changing the javascript commands to load note before doc="""Allows changing the javascript commands to load note before
executing it and do change in the QT editor.""", 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 # Tag
################### ###################
Hook(name="tag_editor_did_process_key", args=["tag_edit: TagEdit", "evt: QEvent"]), Hook(name="tag_editor_did_process_key", args=["tag_edit: TagEdit", "evt: QEvent"]),