implement new dom update algorithm

This commit is contained in:
Kevin Jahns 2017-12-05 21:50:00 -08:00
parent 9c471ea24d
commit ad44f59def
3 changed files with 19 additions and 14 deletions

View File

@ -254,10 +254,8 @@ export default class YXmlFragment extends YArray {
}) })
// Apply Y.Xml events to dom // Apply Y.Xml events to dom
this.observeDeep(events => { this.observeDeep(events => {
this._mutualExclude(() => {
reflectChangesOnDom.call(this, events, _document) reflectChangesOnDom.call(this, events, _document)
}) })
})
// Apply Dom changes on Y.Xml // Apply Dom changes on Y.Xml
if (typeof MutationObserver !== 'undefined') { if (typeof MutationObserver !== 'undefined') {
this._y.on('beforeTransaction', () => { this._y.on('beforeTransaction', () => {

View File

@ -68,7 +68,6 @@ export function afterTransactionSelectionFixer (y, transaction, remote) {
} }
} }
if (shouldUpdate) { if (shouldUpdate) {
console.info('updating selection!!')
browserSelection.setBaseAndExtent( browserSelection.setBaseAndExtent(
anchorNode, anchorNode,
anchorOffset, anchorOffset,

View File

@ -193,19 +193,27 @@ export function reflectChangesOnDom (events, _document) {
* only in the attributes (above) * only in the attributes (above)
*/ */
if (event.childListChanged && yxml.constructor !== YXmlHook) { if (event.childListChanged && yxml.constructor !== YXmlHook) {
// create fragment of undeleted nodes let currentChild = dom.firstChild
const fragment = _document.createDocumentFragment()
yxml.forEach(function (t) { yxml.forEach(function (t) {
fragment.appendChild(t.getDom(_document)) let expectedChild = t.getDom(_document)
}) if (expectedChild.parentNode === dom) {
// remove remainding nodes // is already attached to the dom. Look for it
let lastChild = dom.lastChild while (currentChild !== expectedChild) {
while (lastChild !== null) { let del = currentChild
dom.removeChild(lastChild) currentChild = currentChild.nextSibling
lastChild = dom.lastChild dom.removeChild(del)
}
currentChild = currentChild.nextSibling
} else {
// this dom is not yet attached to dom
dom.insertBefore(expectedChild, currentChild)
}
})
while (currentChild !== null) {
let tmp = currentChild.nextSibling
dom.removeChild(currentChild)
currentChild = tmp
} }
// insert fragment of undeleted nodes
dom.appendChild(fragment)
} }
} }
/* TODO: smartscrolling /* TODO: smartscrolling