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?

TylerH's user avatar

TylerH

21.3k86 gold badges84 silver badges122 bronze badges

micka190's user avatar

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).

micka190's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.