diff --git a/src/Type/y-xml/YXmlFragment.js b/src/Type/y-xml/YXmlFragment.js index 02aaf0bd..6f83dcb8 100644 --- a/src/Type/y-xml/YXmlFragment.js +++ b/src/Type/y-xml/YXmlFragment.js @@ -254,9 +254,7 @@ export default class YXmlFragment extends YArray { }) // Apply Y.Xml events to dom this.observeDeep(events => { - this._mutualExclude(() => { - reflectChangesOnDom.call(this, events, _document) - }) + reflectChangesOnDom.call(this, events, _document) }) // Apply Dom changes on Y.Xml if (typeof MutationObserver !== 'undefined') { diff --git a/src/Type/y-xml/selection.js b/src/Type/y-xml/selection.js index 61618315..428217f0 100644 --- a/src/Type/y-xml/selection.js +++ b/src/Type/y-xml/selection.js @@ -68,7 +68,6 @@ export function afterTransactionSelectionFixer (y, transaction, remote) { } } if (shouldUpdate) { - console.info('updating selection!!') browserSelection.setBaseAndExtent( anchorNode, anchorOffset, diff --git a/src/Type/y-xml/utils.js b/src/Type/y-xml/utils.js index c98c1f82..984553ff 100644 --- a/src/Type/y-xml/utils.js +++ b/src/Type/y-xml/utils.js @@ -193,19 +193,27 @@ export function reflectChangesOnDom (events, _document) { * only in the attributes (above) */ if (event.childListChanged && yxml.constructor !== YXmlHook) { - // create fragment of undeleted nodes - const fragment = _document.createDocumentFragment() + let currentChild = dom.firstChild yxml.forEach(function (t) { - fragment.appendChild(t.getDom(_document)) + let expectedChild = t.getDom(_document) + if (expectedChild.parentNode === dom) { + // is already attached to the dom. Look for it + while (currentChild !== expectedChild) { + let del = currentChild + currentChild = currentChild.nextSibling + dom.removeChild(del) + } + currentChild = currentChild.nextSibling + } else { + // this dom is not yet attached to dom + dom.insertBefore(expectedChild, currentChild) + } }) - // remove remainding nodes - let lastChild = dom.lastChild - while (lastChild !== null) { - dom.removeChild(lastChild) - lastChild = dom.lastChild + while (currentChild !== null) { + let tmp = currentChild.nextSibling + dom.removeChild(currentChild) + currentChild = tmp } - // insert fragment of undeleted nodes - dom.appendChild(fragment) } } /* TODO: smartscrolling