New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
beforeinput: Should we fire replaceContent
during IME composition?
#122
Comments
@choniong: it seems insertText (formerly insertCharacter) is separate from replaceContent because the insertText event is not cancelable during composition and because cE=typing will have a default action for insertText, but not for replaceContent.
That may sound a bit strange, but instead of just selecting one character, the selection could also span over a more complex piece of piece of the DOM. This means it would be difficult to handle the two correctly in JS if the two were merged in cE=typing. One would have to check:
Only if both are true would there be a default action, otherwise no.
Indeed, it seems not all the actions we need can necessarily be defined in terms of execCommand commands, and vice versa. This was just an idea that came out of the browser meeting. It hasn't been discussed or investigated much beyond that. |
@johanneswilm Thanks for the explanation! So if I'm understanding it correctly we only have For example on Mac with Japanese IME pressing the following key:
Do we just fire Here is a demo for the above example: Thanks! |
It is my understanding that we first send deleteComposedCharacter and then insertText to add the new characters. Similarly, if one selects some content, and then starts an IME input session: This will be divided into two steps: first deleteContent (which can be canceled), and if the caret then is collapsed and left in a place where it can insertText, the composition is started there with an insertText event. One difference is of course that during the composition, the beforeInput events are not cancelable and if the selection is moved, the composition ends. Btw, your demo above crashed both Chrome on Android and Linux after about a minute or so. |
OK I see, delete then insert could work. Thanks for the help! And sorry for the crash, I guess I should reduce gif size before uploading... (8MB for this one) |
This seems to have been resolved. Please reopen if incorrect. |
From my understanding
replaceContent
should be fired when the existing text will be changed, for example:insertText
should be fired for each letter)beforeinput
event)replaceContent
should be fired instead ofinsertText
)But for an IME composition text will usually keep changing while typing, and after composition the marked text will be replaced by the final text once again.
So should the browser use the logic like:
insertText
replaceContent
?Also I'm not sure why do we need
replaceContent
instead of usinginsertText
with atargetRanges
? (I could't findreplace*
in https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand#Commands, they only gotinsertText
I guess?)The text was updated successfully, but these errors were encountered: