- From: Masayuki Nakano <notifications@github.com>
- Date: Wed, 04 Sep 2019 00:23:03 -0700
- To: w3c/editing <editing@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/editing/issues/200/527777422@github.com>
> > That means that web apps may want to distinguish whether each `beforeinput` is fired by `execCommand` or not. > > Web apps **do not use `execCommand`** for editing and it's not an option to use it either except for small 5-line demos. As far as I know, some developers want to use only simple `execCommand` for making modification undo-able with browser built-in undo stack. Anyway, not point of this issue. > > I meant that whether `beforeinput` event is dispatched or not when web apps modifies editable contents with API. I meant that if `beforeinput` event is fired only while calling some API, it's inconsistent between API. > > I still don't understand what you're trying to say. It seems more inconsistent for `beforeinput` to not fire in cases where `input` event would otherwise fire. In my understanding, `beforeinput` is suggested for that web apps can cancel or overwrite the behavior of user operation before browsers modify the DOM tree. If somebody want to "correct" characters and make it undo-able without their own transaction manager, they may want to do: ``` editor.addEventListener("beforeinput", (event) => { if (event.inputType === "insertText") { let modifiedData = modifySomething(event.data); if (modifiedData !== event.data) { document.execCommand("insertText", false, modifiedData); event.preventDefault(); } } }); ``` > If someone is writing a library which needs to react to whenever an editing operation gets triggered in a `contenteditable` region (e.g. in order to update corresponding data model), then it needs to listen to such an event regardless of whether it happened due to direct user inputs or `execCommand`. There is no need to distinguish the two. I don't think that `beforeinput` even is a good solution for that purpose because it cannot catch DOM tree modification by DOM API. Isn't mutation observer designed for such purpose? I think that events defined by UI Events are useful only for listening user actions. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/w3c/editing/issues/200#issuecomment-527777422
Received on Wednesday, 4 September 2019 07:23:27 UTC