w3c / input-events

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

Why do textareas and inputs of type "text" return an empty array from getTargetRanges()? #43

Closed whsieh closed 7 years ago

whsieh commented 7 years ago

According to the chart in https://www.w3.org/TR/input-events/, <textarea> and <input type="text"> should return an empty array in getTargetRanges(). It seems like target ranges would be necessary for features such as autocorrect or spellchecking to work properly in plain text areas, otherwise the page would not know what range of text is being replaced.

whsieh commented 7 years ago

@rniwa @johanneswilm @choniong

johanneswilm commented 7 years ago

@whsieh The usual range information doesn't work for <textarea> and <input type="text"> because the DOM doesn't change when you type into the field, and for <input type="text"> because there isn't a textnode within which the selection could be.

The point of the beforeinput event for these two elements is therefore for other purposes. For example, if you want to create your own undo manager for a textarea and want to make sure to record what text is selected before each change so that you can reestablish that selection should the user undo, you can listen to all the beforeinput events and record the current selection/value of the textarea.

whsieh commented 7 years ago

Ah, I see. Thanks for the explanation!