From e531b29307c2e46c6a8a21a03a1469b099d5325b Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 29 Aug 2019 12:50:23 +0200 Subject: [PATCH] don't ignore BR elements when converting to editor dom to text --- src/editor/dom.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/editor/dom.js b/src/editor/dom.js index 1b683c2c5e..4f15a57303 100644 --- a/src/editor/dom.js +++ b/src/editor/dom.js @@ -84,6 +84,14 @@ function getTextAndFocusNodeOffset(editor, focusNode, focusOffset) { foundCaret = true; } } + // usually newlines are entered as new DIV elements, + // but for example while pasting in some browsers, they are still + // converted to BRs, so also take these into account when they + // are not the last element in the DIV. + if (node.tagName === "BR" && node.nextSibling) { + text += "\n"; + focusNodeOffset += 1; + } const nodeText = node.nodeType === Node.TEXT_NODE && getTextNodeValue(node); if (nodeText) { if (!foundCaret) {