Skip to content

Commit

Permalink
Fix moving backwards across astral chars
Browse files Browse the repository at this point in the history
Closes #6544
  • Loading branch information
marijnh committed Dec 29, 2020
1 parent 863c189 commit 37d7b2e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/edit/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,12 @@ function findPosH(doc, pos, dir, unit, visually) {
let next
if (unit == "codepoint") {
let ch = lineObj.text.charCodeAt(pos.ch + (unit > 0 ? 0 : -1))
if (isNaN(ch)) next = null
else next = new Pos(pos.line, Math.max(0, Math.min(lineObj.text.length, pos.ch + dir * (ch >= 0xD800 && ch < 0xDC00 ? 2 : 1))),
-dir)
if (isNaN(ch)) {
next = null
} else {
let astral = dir > 0 ? ch >= 0xD800 && ch < 0xDC00 : ch >= 0xDC00 && ch < 0xDFFF
next = new Pos(pos.line, Math.max(0, Math.min(lineObj.text.length, pos.ch + dir * (astral ? 2 : 1))), -dir)
}
} else if (visually) {
next = moveVisually(doc.cm, lineObj, pos, dir)
} else {
Expand Down

0 comments on commit 37d7b2e

Please sign in to comment.