w3c / input-events

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

beforeinput for intentions that do not yet change anything + cancelation? #64

Open johanneswilm opened 7 years ago

johanneswilm commented 7 years ago

Hey, as I was editing the spec with the comments from the TAG review, it hit me that for some formatting, we let the user epxress intentions to add formatting to content that does not yet exist. For example, take the following example:

1 The user hits a "bold" button while the selection is collapsed. The DOM does not yet change.

2a The user types the first letter. The default action would be to encapsulate that first letter an element that adds the bold styling, for example "<b>A</b>", or

2b The user gets a different idea and changes the selection. There should be no change to the DOM at all.

2c The user gets a different idea, but does not want to change the selection, so he hits the "bold" button a second time to undo the initiation of bold executed in 1.

So the two questions are:

  1. When should the beforeinput event be triggered? As part of 1 or 2?

If we do it as part of 1, then surely the beforeinput and input events won't be paired perfectly.

If we do it as part of 2, do we then differentiate between a beforeinput event for formatBold and one for insertText for the "A"? What if the the selection in 2b is changed not due to the user but due to the JS moving the selection around (the JS can't really know it shouldn't do that)?

  1. If we record the user's expression of intent to activate bold in 1, should we then not also be able to record the cancelation of that intention (2c)?
johanneswilm commented 7 years ago

@reinmar I believe you were talking about something similar a while back anbd this is why we changed the definition of the formatting commands to also apply in these cases where there is no actual change to the DOM, right?