forked from basecamp/trix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the target range to insert the replacement text
When the browser auto-corrects a misspelled word, it dispatches a `beforeinput` event with the `insertReplacementText` input type and a `dataTransfer` object containing the replacement text. The event also contains a `getTargetRanges` method that returns an array of `DOMRange` objects representing the range of text that will be replaced. When the `Level2InputController` was originally implemented, not all browsers supported the `getTargetRanges` method, so it was not used. Now that all supported browsers do support `getTargetRanges`, we can use it to insert the replacement text at the correct location. This ensures editor state is updated correctly the cursor is positioned correctly. Ref. - https://w3c.github.io/input-events/#overview (search for "insertReplacementText") - https://developer.mozilla.org/en-US/docs/Web/API/InputEvent/getTargetRanges
- Loading branch information
Showing
3 changed files
with
16 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters