Re: [w3c/editing] Universal interface to modify content in a JS editor from unrelated JS code. (Issue #551)

GaurangTandon left a comment (w3c/editing#551)

Thanks for trying out my fork! I think we may have been looking at different buttons.

After building the site, please install the extension (from `vendor/extension/`). Then, visit http://localhost:8080/extension.html and click the "_Replace via execCommand_" button. I [recorded a video on Chrome](https://docs.google.com/videos/d/1V6ipitUI78fiTrgBVqFVETUqnQAe1b46Cu1vKBjCl0c/play?usp=sharing) to ensure we're on the same page. This button works for all six (non-EditContext) editors, and it does not add any nbsp artifacts (as shown in the video via the "artifacts" line). I also updated the code in my fork to avoid confusion (by highlighting the relevant button and adding a warning if the extension isn't installed).

On the technical level, this button reaches `function execInsert` in `apply-edit.js`, which fires 'paste' (trusted), then dispatches 'beforeinput' (synthetic) from inside the paste handler, then 'input' (trusted), all in the same order as a real user paste.

My point is that the extension shouldn't need to know which of paste, beforeinput or input an editor listens to. The extension can just use `execCommand("paste")`, which already behaves (almost) identically to a real user paste (as shown above). The only manual part is the synthetic beforeinput needed only on Chrome. Once Chrome fires a trusted 'beforeinput' for `execCommand("paste")`, it would be a reliable interface for browser extension scripts (the "unrelated JS code") to insert text in a non-EditContext JS editor.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/editing/issues/551#issuecomment-6055982775
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/editing/issues/551/6055982775@github.com>

Received on Thursday, 8 October 2026 08:34:00 UTC