Skip to content

Commit 01fe6ca

Browse files
muanmarijnh
authored andcommitted
Extra line breaks for blocky elements
1 parent 04298bb commit 01fe6ca

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/input/ContentEditableInput.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,13 @@ function isInGutter(node) {
396396
function badPos(pos, bad) { if (bad) pos.bad = true; return pos }
397397

398398
function domTextBetween(cm, from, to, fromLine, toLine) {
399-
let text = "", closing = false, lineSep = cm.doc.lineSeparator()
399+
let text = "", closing = false, lineSep = cm.doc.lineSeparator(), extraLinebreak = false
400400
function recognizeMarker(id) { return marker => marker.id == id }
401401
function close() {
402402
if (closing) {
403403
text += lineSep
404-
closing = false
404+
if (extraLinebreak) text += lineSep
405+
closing = extraLinebreak = false
405406
}
406407
}
407408
function addText(str) {
@@ -431,9 +432,11 @@ function domTextBetween(cm, from, to, fromLine, toLine) {
431432
if (isBlock) close()
432433
for (let i = 0; i < node.childNodes.length; i++)
433434
walk(node.childNodes[i])
435+
436+
if (/^(pre|p)$/i.test(node.nodeName)) extraLinebreak = true
434437
if (isBlock) closing = true
435438
} else if (node.nodeType == 3) {
436-
addText(node.nodeValue.replace(/\u00a0/g, " ").replace(/\u200b/g, ""))
439+
addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "))
437440
}
438441
}
439442
for (;;) {

0 commit comments

Comments
 (0)