Skip to content

Commit a29a6b0

Browse files
committed
Add IMG hack nodes to the end of the last mark, rather than after them
FIX: Work around a hidden cursor issue in Chrome when a textblock ends in an uneditable node wrapped in a mark. Issue ProseMirror/prosemirror#1261
1 parent 97faf30 commit a29a6b0

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/viewdesc.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,21 +1264,24 @@ class ViewTreeUpdater {
12641264
// Make sure a textblock looks and behaves correctly in
12651265
// contentEditable.
12661266
addTextblockHacks() {
1267-
let lastChild = this.top.children[this.index - 1]
1268-
while (lastChild instanceof MarkViewDesc) lastChild = lastChild.children[lastChild.children.length - 1]
1267+
let lastChild = this.top.children[this.index - 1], parent = this.top
1268+
while (lastChild instanceof MarkViewDesc) {
1269+
parent = lastChild
1270+
lastChild = parent.children[parent.children.length - 1]
1271+
}
12691272

12701273
if (!lastChild || // Empty textblock
12711274
!(lastChild instanceof TextViewDesc) ||
12721275
/\n$/.test(lastChild.node.text)) {
12731276
// Avoid bugs in Safari's cursor drawing (#1165) and Chrome's mouse selection (#1152)
12741277
if ((browser.safari || browser.chrome) && lastChild && lastChild.dom.contentEditable == "false")
1275-
this.addHackNode("IMG")
1276-
this.addHackNode("BR")
1278+
this.addHackNode("IMG", parent)
1279+
this.addHackNode("BR", this.top)
12771280
}
12781281
}
12791282

1280-
addHackNode(nodeName) {
1281-
if (this.index < this.top.children.length && this.top.children[this.index].matchesHack(nodeName)) {
1283+
addHackNode(nodeName, parent) {
1284+
if (parent == this.top && this.index < parent.children.length && parent.children[this.index].matchesHack(nodeName)) {
12821285
this.index++
12831286
} else {
12841287
let dom = document.createElement(nodeName)
@@ -1287,7 +1290,9 @@ class ViewTreeUpdater {
12871290
dom.alt = ""
12881291
}
12891292
if (nodeName == "BR") dom.className = "ProseMirror-trailingBreak"
1290-
this.top.children.splice(this.index++, 0, new TrailingHackViewDesc(this.top, nothing, dom, null))
1293+
let hack = new TrailingHackViewDesc(this.top, nothing, dom, null)
1294+
if (parent != this.top) parent.children.push(hack)
1295+
else parent.children.splice(this.index++, 0, hack)
12911296
this.changed = true
12921297
}
12931298
}

0 commit comments

Comments
 (0)