Skip to content

Commit

Permalink
Work around iOS select-all misbehavior
Browse files Browse the repository at this point in the history
FIX: Work around odd iOS Safari behavior when doing select all.

Closes codemirror/dev#1304
  • Loading branch information
marijnh committed Dec 14, 2023
1 parent 7cb7d5b commit a756561
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/domchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export class DOMChange {
!contains(view.contentDOM, domSel.anchorNode)
? view.state.selection.main.anchor
: view.docView.posFromDOM(domSel.anchorNode!, domSel.anchorOffset)
// iOS will refuse to select the block gaps when doing select-all
if (browser.ios && view.state.selection.main.empty && head != anchor) {
let offFrom = view.viewport.from - Math.min(head, anchor), offTo = view.viewport.to - Math.max(head, anchor)
if ((offFrom == 0 || offFrom == 1) && (offTo == 0 || offTo == -1)) {
head = 0
anchor = view.state.doc.length
}
}
this.newSel = EditorSelection.single(anchor, head)
}
}
Expand Down

0 comments on commit a756561

Please sign in to comment.