Force mungeHTML after webview edit (simulate typing?)

When I edit the innerHTML of a field’s editingArea.editable, the changes are saved only after focusing it manually.

@hengiesel I’m struggling to figure out how Closet manages to force the editor to save field content changes made via JS (specifically insert_into_zero_indexed and activate_matching_fields).

You called the file “”, but I can’t make out the simulation part. I see you’re using editor.web.evalWithCallback, is that the secret?

Basically I first get the HTML content of the field into python, make some changes to it, and then pass it back to Javascript. I think the most important part is this:

cmd = (
    f'pycmd(`key:{field_index}:${{getNoteId()}}:{escaped}`); '
    f'getEditorField({field_index}).editingArea.fieldHTML = `{escaped}`; '

pycmd (or better, bridgeCommand) will tell the backend, what the field’s content is now. Afterwards you need to update the field in the webview itself (otherwise, the next key or blur event will revert the change).


Thank you Henrik, works like a charm! :metal:

1 Like