Skip to content

Commit

Permalink
Fix caret move on iOS 17
Browse files Browse the repository at this point in the history
There's an issue with iOS 17 where if you move the caret and then press
backwards, for example because you made a typo, the caret will jump to
its previous position. This is because on the onselectionchange event
the event handler doesn't see the caret move as a new DOM range. It thinks
the DOM range is the same as before and doesn't notify the registered
observers.

If we receive an onselectionchange event and the selection type is "Caret"
that means the caret moved and we should notify the observers, regardless
of whether the DOM range is the same as before.
  • Loading branch information
afcapel committed Sep 22, 2023
1 parent ade9bc0 commit 52dd480
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/trix/observers/selection_change_observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export default class SelectionChangeObserver extends BasicObject {

update() {
const domRange = getDOMRange()
if (!domRangesAreEqual(domRange, this.domRange)) {
const caretMove = window.getSelection().type === "Caret"

if (!domRangesAreEqual(domRange, this.domRange) || caretMove) {
this.domRange = domRange
return this.notifySelectionManagersOfSelectionChange()
}
Expand Down

0 comments on commit 52dd480

Please sign in to comment.