Skip to content

Commit

Permalink
Fix context menu select all on chrome when the start of doc isn't in …
Browse files Browse the repository at this point in the history
…viewport

FIX: Fix an issue that broke context-menu select-all on Chrome when
the viewport didn't cover the whole document.

Closes codemirror/dev#1321
  • Loading branch information
marijnh committed Jan 25, 2024
1 parent 1743fdf commit f1a7b2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/docview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ class BlockGapWidget extends WidgetType {
get editable() { return true }

get estimatedHeight() { return this.height }

ignoreEvent() { return false }
}

export function findCompositionNode(view: EditorView, headPos: number): {from: number, to: number, node: Text} | null {
Expand Down
12 changes: 8 additions & 4 deletions src/domchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ 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
// iOS will refuse to select the block gaps when doing
// select-all.
// Chrome will put the selection *inside* them, confusing
// posFromDOM
let vp = view.viewport
if (browser.ios && view.state.selection.main.empty && head != anchor &&
if ((browser.ios || browser.chrome) && view.state.selection.main.empty && head != anchor &&
(vp.from > 0 || vp.to < view.state.doc.length)) {
let offFrom = vp.from - Math.min(head, anchor), offTo = vp.to - Math.max(head, anchor)
if ((offFrom == 0 || offFrom == 1) && (offTo == 0 || offTo == -1)) {
let from = Math.min(head, anchor), to = Math.max(head, anchor)
let offFrom = vp.from - from, offTo = vp.to - to
if ((offFrom == 0 || offFrom == 1 || from == 0) && (offTo == 0 || offTo == -1 || to == view.state.doc.length)) {
head = 0
anchor = view.state.doc.length
}
Expand Down

0 comments on commit f1a7b2c

Please sign in to comment.