handle contenteditable correctly

This commit is contained in:
Leo 2016-11-02 13:15:43 -04:00
parent 387a69615d
commit 75b7f0fc81
3 changed files with 78 additions and 50 deletions

View file

@ -499,11 +499,14 @@ var _14 = function($window) {
if (attrs2 != null) {
setAttrs(vnode, attrs2, ns)
}
if (vnode.text != null) {
if (vnode.attrs != null && vnode.attrs.contenteditable != null) {
setContentEditable(vnode)
}
else if (vnode.text != null) {
if (vnode.text !== "") element.textContent = vnode.text
else vnode.children = [Vnode("#", undefined, undefined, vnode.text, undefined, undefined)]
}
if (vnode.children != null) {
else if (vnode.children != null) {
var children = vnode.children
createNodes(element, children, 0, children.length, hooks, null, ns)
setLateAttrs(vnode)
@ -667,7 +670,10 @@ var _14 = function($window) {
}
}
updateAttrs(vnode, old.attrs, vnode.attrs, ns)
if (old.text != null && vnode.text != null && vnode.text !== "") {
if (vnode.attrs != null && vnode.attrs.contenteditable != null) {
setContentEditable(vnode)
}
else if (old.text != null && vnode.text != null && vnode.text !== "") {
if (old.text.toString() !== vnode.text.toString()) old.dom.firstChild.nodeValue = vnode.text
}
else {
@ -740,6 +746,14 @@ var _14 = function($window) {
if (nextSibling && nextSibling.parentNode) parent0.insertBefore(dom, nextSibling)
else parent0.appendChild(dom)
}
function setContentEditable(vnode) {
var children = vnode.children
if (children != null && children.length === 1 && children[0].tag === "<") {
var content = children[0].children
if (vnode.dom.innerHTML !== content) vnode.dom.innerHTML = content
}
else if (children != null || vnode.text != null) throw new Error("Child node of a contenteditable must be trusted")
}
//remove
function removeNodes(parent0, vnodes, start, end, context) {
for (var i = start; i < end; i++) {