Skip to content

Commit

Permalink
Fix an issue in the way the DOMReader treats positions in opaque nodes
Browse files Browse the repository at this point in the history
FIX: Fix an issue in the way the DOM selection is being read that could break
backspacing of widgets on Android.

See https://discuss.codemirror.net/t/backspace-on-decoration-work-strangely-in-mobile-keyboard/7009
  • Loading branch information
marijnh committed Sep 22, 2023
1 parent 4112542 commit 47ffaf9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/domreader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ContentView} from "./contentview"
import {domIndex, maxOffset} from "./dom"
import {EditorState} from "@codemirror/state"

export const LineBreakPlaceholder = "\uffff"
Expand Down Expand Up @@ -88,10 +89,19 @@ export class DOMReader {
point.pos = this.text.length
}

findPointInside(node: Node, maxLen: number) {
findPointInside(node: Node, length: number) {
for (let point of this.points)
if (node.nodeType == 3 ? point.node == node : node.contains(point.node))
point.pos = this.text.length + Math.min(maxLen, point.offset)
point.pos = this.text.length + (isAtEnd(node, point.node, point.offset) ? length : 0)
}
}

function isAtEnd(parent: Node, node: Node | null, offset: number) {
for (;;) {
if (!node || offset < maxOffset(node)) return false
if (node == parent) return true
offset = domIndex(node) + 1
node = node.parentNode
}
}

Expand Down

0 comments on commit 47ffaf9

Please sign in to comment.