Skip to content

Commit 692393d

Browse files
committed
Drop zero-width spaces in text read from DOM
Issue codemirror#4307
1 parent 333a1f2 commit 692393d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/input/ContentEditableInput.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ ContentEditableInput.prototype = copyObj({
282282
newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
283283
++cutEnd
284284

285-
newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd)
286-
newText[0] = newText[0].slice(cutFront)
285+
newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "")
286+
newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "")
287287

288288
let chFrom = Pos(fromLine, cutFront)
289289
let chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0)
@@ -361,8 +361,8 @@ function domTextBetween(cm, from, to, fromLine, toLine) {
361361
if (node.nodeType == 1) {
362362
let cmText = node.getAttribute("cm-text")
363363
if (cmText != null) {
364-
if (cmText == "") cmText = node.textContent.replace(/\u200b/g, "")
365-
text += cmText
364+
if (cmText == "") text += node.textContent.replace(/\u200b/g, "")
365+
else text += cmText
366366
return
367367
}
368368
let markerID = node.getAttribute("cm-marker"), range

0 commit comments

Comments
 (0)