ARTICLE AD BOX
When handling the beforeinput event, how do I determine the range affected by an inputType of "deleteWordForward" or "deleteWordBackward"? These occur when the user does ctrl+Delete or ctrl+Backspace.
The target input's selectionStart and selectionEnd are at the caret's index, not at the bounds of whatever the browser determines to be a "word".
There seems to be some special handling for whitespace. Sometimes, a leading or trailing whitespace is included in the "word", but sometimes it isn't (varies between single whitespace vs multiple whitespace).
Is this behavior standardized across browsers? Are they all using some kind of Regular Expression I could use? If so, is this documented anywhere?
3
Neither the Input Events Level 1 or Input Events Level 2 specs define how word boundaries could be accessed by an event handler. I think it's safe to assume there's no way of doing it that's provided by the browser.
Additionally, I've looked discussions surrounding browser specifications. While not directly related to the beforeinput event, these two discussions are related to word boundaries, and how browsers handle them:
Different browser behaviors when moving the caret by one word. Specify Selection.modify()?The consensus seems to be that browsers each implement word boundary handling themselves. Some let the OS handle it, while others handle it themselves.
As far as using a Regex, that won't work, since some languages require heuristics to determine word boundaries (i.e., Chinese and Japanese sometimes require dictionary lookups for their more complex characters).
1,0322 gold badges12 silver badges32 bronze badges
Explore related questions
See similar questions with these tags.
