w3c / input-events

Input Events
https://w3c.github.io/input-events/
Other
23 stars 16 forks source link

What should happen when insertFromComposition is canceled #41

Open rniwa opened 7 years ago

rniwa commented 7 years ago

When insertFromComposition is canceled, we can't continue to have the text being composited since UA doesn't have the capability to keep input methods and keyboards open in some platforms. i.e. we need to remove the currently composting text from DOM.

There are two behaviors we can implement:

Fire another insertCompositionText to replace the composition with an empty string when insertFromComposition is canceled. Before firing insertFromComposition, fire another insertFromComposition to replace the composition text with an empty string just like we do in deleteByComposition before starting composition. (1) is weird because it would mean that we would fire an extra composition event after the composition had logically ended.

(2) makes sense because we already delete the existing content with deleteByComposition before entering input methods in reconversion case. We're simply following the same pattern when we're exiting the composition by first emptying the composing text, and then inserting the confirmed text.

rniwa commented 7 years ago

@choniong @whsieh @ojanvafai

johanneswilm commented 7 years ago

@rniwa Isn't the current setup the same as your option 2 as the entire composition string is deleted with a non-cancelable "deleteCompositionText" before the "insertFromComposition"?

Also, see this note: https://w3c.github.io/input-events/#h-note4

chong-z commented 7 years ago

(Wrong button sorry...)

Same as what @johanneswilm said, but the assumption was UA always do full text replacing.

In fact we probably want to loose the restriction as UA might want to optimize the replacing algorithm (e.g. To preserve style.) when 'insertFromComposition' was not cancelled. Will file a separate issue for this.

whsieh commented 7 years ago

Thank you for your responses, @johanneswilm and @choniong! To reiterate, when the user commits the composed text to the DOM, we:

  1. Dispatch a non-cancelable beforeinput event of type "deleteCompositionText"
  2. Remove the composition text
  3. Dispatch an input event of type "deleteCompositionText"
  4. Dispatch a cancelable beforeinput event of type "insertFromComposition"
  5. If (4) was not prevented, then reinsert the final composition text into the DOM and dispatch an input event of type "insertFromComposition"

Does this sound right?

johanneswilm commented 7 years ago

@whsieh Yes, that sounds right.