Skip to content

Commit 6019b13

Browse files
committed
[contenteditable input] Expand scanned range when selection at start/end of line
So that the code doesn't get confused when backspacing or deleting across a line. This is still flaky. Ideally we'd capture backspace as a key event, but Android Chrome makes that impossible. Issue codemirror#4307
1 parent d7b1370 commit 6019b13

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/input/ContentEditableInput.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ ContentEditableInput.prototype = copyObj({
238238

239239
let cm = this.cm, display = cm.display, sel = cm.doc.sel.primary()
240240
let from = sel.from(), to = sel.to()
241+
if (from.ch == 0 && from.line > cm.firstLine())
242+
from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length)
243+
if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine())
244+
to = Pos(to.line + 1, 0)
241245
if (from.line < display.viewFrom || to.line > display.viewTo - 1) return false
242246

243247
let fromIndex, fromLine, fromNode
@@ -258,6 +262,7 @@ ContentEditableInput.prototype = copyObj({
258262
toNode = display.view[toIndex + 1].node.previousSibling
259263
}
260264

265+
if (!fromNode) return false
261266
let newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine))
262267
let oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length))
263268
while (newText.length > 1 && oldText.length > 1) {

0 commit comments

Comments
 (0)