Skip to content
Snippets Groups Projects
Commit 04298bbf authored by Mu-An ✌️ Chiou's avatar Mu-An ✌️ Chiou Committed by Marijn Haverbeke
Browse files

Fix IE11 pasting losing line breaks

- walk child of [cm-text] if [cm-text] is empty in order to find line breaks
- treat br/li/table as blocks
- always addText from on textNode not node.textContent
parent 7677433d
No related branches found
No related tags found
No related merge requests found
...@@ -413,8 +413,8 @@ function domTextBetween(cm, from, to, fromLine, toLine) { ...@@ -413,8 +413,8 @@ function domTextBetween(cm, from, to, fromLine, toLine) {
function walk(node) { function walk(node) {
if (node.nodeType == 1) { if (node.nodeType == 1) {
let cmText = node.getAttribute("cm-text") let cmText = node.getAttribute("cm-text")
if (cmText != null) { if (cmText) {
addText(cmText || node.textContent.replace(/\u200b/g, "")) addText(cmText)
return return
} }
let markerID = node.getAttribute("cm-marker"), range let markerID = node.getAttribute("cm-marker"), range
...@@ -425,13 +425,15 @@ function domTextBetween(cm, from, to, fromLine, toLine) { ...@@ -425,13 +425,15 @@ function domTextBetween(cm, from, to, fromLine, toLine) {
return return
} }
if (node.getAttribute("contenteditable") == "false") return if (node.getAttribute("contenteditable") == "false") return
let isBlock = /^(pre|div|p)$/i.test(node.nodeName) let isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName)
if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) return
if (isBlock) close() if (isBlock) close()
for (let i = 0; i < node.childNodes.length; i++) for (let i = 0; i < node.childNodes.length; i++)
walk(node.childNodes[i]) walk(node.childNodes[i])
if (isBlock) closing = true if (isBlock) closing = true
} else if (node.nodeType == 3) { } else if (node.nodeType == 3) {
addText(node.nodeValue.replace(/\u00a0/g, " ")) addText(node.nodeValue.replace(/\u00a0/g, " ").replace(/\u200b/g, ""))
} }
} }
for (;;) { for (;;) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment