-
Notifications
You must be signed in to change notification settings - Fork 51
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
Event order between "compositionend" and "input" #202
Comments
So, I think that isComposing of "beforeinput" followed by "compositionend" should be true, but isComposing of "input" event caused by committing composition should be false. |
The problem with this is that you cannot detect anymore whether the input that caused |
Is there a particular use case you have in mind where you need to make this distinction? |
Another possible solution is, UI Events would change the declaration of InputEvent.isComposing. It's currently declared as "true if the input event occurs as part of a composition session, i.e., after a compositionstart event and before the corresponding compositionend event.", however, if it's declared as the value of input events which are fired for committing composition is set to false, web apps need to check only input events whose isComposing is false (like running on Firefox and Edge). |
@Kovensky What do you think of the proposal that we match the order of WebKit/Blink (and now the spec) but make the last I think that would allow making the distinction you mentioned and, like @masayuki-nakano mentions, would mean that for many apps that want to ignore input during composition, they can simply ignore |
I remember having issues with Japanese IME input because the This was a few months ago, though, I don't remember if/how that was dealt with. |
That's a fair point. I hadn't thought about multi-line input so much. So with the proposal to make
Does that sound right? (I'm actually a bit confused now about if this proposal works in light of multiple |
Currently, DOM composition events do not support of committing a part of composition. In such case, Firefox commits existing composition first, then, restart composition with new range. Brian, you can check this behavior even with MS-IME.
And also, new line key handling is not defined under UI Events unfortunately. In most cases, Enter key press during composition of Japanese IME just commits composition. However, for example, Enter key press during composition of Korean IME causes both committing composition and inserting a new line. If all browsers support beforeinput, the new line input can be represented with it which should be fired immediately after compositionend. However, now, Firefox dispatches a set of key events (i.e., keydown, keypress and keyup events) after compositionend on Windows, and dispatches only keypress event after compositionend on macOS. So, this issue should be out of scope of this. |
Oh, I see. The spec seems to suggest there should be no extra
But I notice neither Chrome nor Firefox do that. For my reference I am testing using this pen: https://codepen.io/birtles/pen/pZwNPx Following the stems from Masayuki for MS-IME:
I get in Firefox:
In Chrome:
Edge:
If some Korean IMEs allow Enter to do double-duty as committing a composition and entering a newline then it sounds like distinguishing between the two actions is a separate matter as you say. If So it sounds like the proposal to make the last input event before the compositionend event have |
Sorry for the delays responding on that issue. I've been finishing other things up and am just now starting to be able to spend more time on UIEvents. To summarize my understanding:
Regarding that last concern, I just tested this on Chrome Win and Mac with Korean and Japanese IMEs and noticed the following events after pressing
So (from this limited testing), I don't think there's a problem with distinguishing the final As for the proposal, other than it makes the spec description more complex, I don't see serious problems with it. But I also don't have a sense of how serious the original problem is. The tradeoff we're making is between:
But it doesn't seem (to me) like it's very common to need to distinguish between input events that are inside or outside composition. The vast majority of devs won't care. The one case I can think of where someone might want to do this is for devs writing rich text editors, but I don't consider it a problem if they have to write a bit more code to get things done - they're probably handling Unless there's a real dev need to fix this, I'd rather keep the definition for
I was wondering where this came from (it's not in the UIEvents spec) and finally found it as a non-normative note in Input Events spec (in Step 5) (https://www.w3.org/TR/input-events-2/). AIUI, that is wrong. The UIEvents spec says (https://www.w3.org/TR/uievents/#events-compositionevents):
|
Thanks for following up on this!
That priority of constituencies here surely means we should choose the latter (i.e. devs > spec writers).
I disagree. @masayuki-nakano has already indicated that it is common to make this distinction in Firefox source. In my work on Web apps too, I frequently need to make this distinction. Some common examples include:
|
How about: "
I have no idea what the use-case of ignoring all input caused by composition. I suggested current |
I phrased that poorly. My concern is not for the spec writer (who only has to write it once), but for anyone who has to read the spec. A more complex spec is more complex for anyone who has to read it or any follow-on documentation (like MDN) that are based on the spec.
But needing to make this distinction in FF code isn't a good reason to expose this to the web platform.
These are compelling examples. Thanks for taking the time to write them up. These are good cases for motivating this change. Would it be sufficient to phrase this as something like: AUIU, if the user cancels composition, the final Does the final |
Thanks for following up on this.
Yes, sorry, by FF code I meant Firefox front-end code, i.e. the JS used for the FF user interface. While it's not entirely representative of typical Web content, for the purposes of handling input events I think it's reasonably close.
I'm not familiar with the correct terminology here but that seems to match the intention at least. @masayuki-nakano does this sound right? The idea behind this language is that it then covers the cancel case too.
@masayuki-nakano what do you think about this? ↑ |
Firefox's front-end is one of the biggest web-applications in the world even though it uses some special API to access sensitive area. So, I believe that if some spec changes make Firefox's front-end more complicated, that means that web apps in the world are also made complicated if they need to implement similar feature.
Honestly, I'm still not sure, I'm still thinking this... From a point of view of web browser, browser has not been handled native commit event yet at dispatching On the other hand, So, most important thing is, which value can prevent bugs of web apps... |
Today Masayuki and I discussed whether or not Argument for making
Argument for making
|
No, you understand my arguing points perfectly. So, |
I ran into this again, but this time not even with In Safari, |
@Kovensky I'm not sure I understand what you're suggesting here. Are you endorsing the importance of this issue or suggesting a particular value of |
It is the importance of this issue, although this kinda looks like a Safari bug instead. The value of |
Most web apps don't do text editing at all, and those 99% won't care, I agree. But what we need to look at are the 1% (or less) of devs working on editing apps. Without such editing apps, there is no content on the web so even if the percentage is low, it does matter for the web overall. Those web apps doing text editing need to be concerned with the difference between composing and non-composing as they are prohibited from changing the DOM around the composition while it takes place. So as long as that is clearly communicated in some way, I think everything is fine.
If That is not really ideal as we are then moving away from the idea that you can build an editor by listening to |
I believe when we originally wrote the level 2 input events spec, our information was that the last input event may not give us information about the contents and placement of the entire composition string. And also at that start, when a composition is initiated on a pre-existing string, we would not know where that string is. This is why we added the cancelable Without those events, as in level 1, the only important piece of information we can listen for is when the composition has finished. Once that has happened, we diff the DOM and find out what has changed, based on that make a guess on what the user wanted to enter/delete, and then act upon that. So unless something has changed so that one can always know where the entire string was placed based on the information of the last input event during composition and what has changed, I don't know if this is of much help to webapps. |
Even if browser only supports Input Events Level 1 (like Firefox and Chrome), |
I came across this as a problem for my own use case where I discovered that Safari/Chrome were triggering I don't have the level of expertise to contribute towards a solution here, but it seems that there was some productive conversation in this thread which dried out and didn't end up leading anywhere. Is this viewed as a non-issue? What should developers be doing to avoid triggering incorrect events on keyboard events which are actually due to international character composition? |
Yes, it would be good to reach consensus on this. I believe we were proposing to change the value of For what it's worth I also often encounter this issue, e.g. this code which is precisely the sort of code Masayuki mentioned at this beginning of this issue. |
It seems like there are good arguments here for Chromium and Safari converging to Firefox's behavior and updating the spec accordingly. @mustaqahmed, would you be the right owner for this for Chrome, or do you know who could make that call? @annevk is this something you'd be able to comment on for Safari? |
How often are these events used? I'd be a bit worried about web compatibility, but perhaps with Chromium and WebKit changing this around the same time that can be mitigated somewhat. cc @whsieh |
@garykac: do you know who could answer the Chrome question above? |
Pretty often. Apart from the issues linked to this one, there are plenty of blogs of people stumbling due to this, e.g.:
Just trying to distinguish an Enter keypress to commit a selection from a regular Enter keypress (e.g. to close a modal) is really hard in Safari. (The most reliable way being to use the deprecated |
A new web-compat bug was filed caused by the event order difference. The app sets |
I'm trying to dispatch redundant (I'm really hoping that this issue will be fixed soon...) |
…`input` event with a new pref r=m_kato The reported web site in bug 1910865 sets `HTMLInputElement.value` to the latest value explicitly at every `input` event except when during a composition. When it's in a composition, it stores the latest value at `input` events during the composition and set it at `compositionend` event listener. Currently, Gecko dispatches the events as the following order at ending a composition: 1. `beforeinput` whose `isComposing` is `true` 2. `compositionend` 3. `input` whose `isComposing` is `false` Therefore, if user chooses the commit string from the candidate list, the commit string is not notified by `input` event before the `compositionend`. On the other hand, Chrome dispatch the events as the following order: 1. `beforeinput` whose `isComposing` is `true` 2. `input` whose `isComposing` is `true` 3. `compositionend` I.e., no `input` event is fired after `compositionend` and there is no `input` event whose `isComposing` is `false`. This is handled in the spec issue [1], but not yet resolved. Perhaps, we can dispatch redundant `input` event before `compositionend` event, i.e., 1. `beforeinput` whose `isComposing` is `true` 2. `input` whose `isComposing` is `true` 3. `compositionend` 4. `input` whose `isComposing` is `false` This breaks the pair of `beforeinput` and `input`, but I guess it's not important for web apps especially for the redundant `input` event case. 1. w3c/uievents#202 Differential Revision: https://phabricator.services.mozilla.com/D234620
…`input` event with a new pref r=m_kato The reported web site in bug 1910865 sets `HTMLInputElement.value` to the latest value explicitly at every `input` event except when during a composition. When it's in a composition, it stores the latest value at `input` events during the composition and set it at `compositionend` event listener. Currently, Gecko dispatches the events as the following order at ending a composition: 1. `beforeinput` whose `isComposing` is `true` 2. `compositionend` 3. `input` whose `isComposing` is `false` Therefore, if user chooses the commit string from the candidate list, the commit string is not notified by `input` event before the `compositionend`. On the other hand, Chrome dispatch the events as the following order: 1. `beforeinput` whose `isComposing` is `true` 2. `input` whose `isComposing` is `true` 3. `compositionend` I.e., no `input` event is fired after `compositionend` and there is no `input` event whose `isComposing` is `false`. This is handled in the spec issue [1], but not yet resolved. Perhaps, we can dispatch redundant `input` event before `compositionend` event, i.e., 1. `beforeinput` whose `isComposing` is `true` 2. `input` whose `isComposing` is `true` 3. `compositionend` 4. `input` whose `isComposing` is `false` This breaks the pair of `beforeinput` and `input`, but I guess it's not important for web apps especially for the redundant `input` event case. 1. w3c/uievents#202 Differential Revision: https://phabricator.services.mozilla.com/D234620
Currently, UI Events declares event order of "compositionend" and "input" as:
At https://w3c.github.io/uievents/#events-composition-input-events
However, Firefox and Edge's order is:
I.e., "input" event is fired after "compositionend".
On the other hand, Chrome and Safari dispatches as the spec declared.
I tried to make Firefox take the same event order as the draft in https://bugzilla.mozilla.org/show_bug.cgi?id=1305387. However, after changing the order, I needed following change in some places even in Firefox's UI: https://hg.mozilla.org/try/rev/9dbba7ff1d6f7f72a33dccc93fdda60f04d9942e
Then, I feel that the event order of Chrome, Safari and the spec does not make sense for web application developers. The reason is, if all browsers use the event order of Firefox and Edge, isComposing value of "input" event becomes false. So, if a web application needs to do something at every input except during composition, web application needs to listen to only input event if it's run on Firefox or Edge. I.e., can be implemented like:
On the other hand, it's run on Chrome or Safari, needs to be implemented like:
I believe that the behavior of Chrome, Safari and UI Events may make web applications not aware of IME.
From point of view of browser developer, this behavior is easier to implement actually since browser does not check whether it's followed by compositionend event when it tries to fire "input" event at every composition change. However, usefulness for web application developers must be more important than easier to implement by browsers.
What do you think, @garykac ?
The text was updated successfully, but these errors were encountered: