implement new dom update algorithm
This commit is contained in:
		
							parent
							
								
									9c471ea24d
								
							
						
					
					
						commit
						ad44f59def
					
				@ -254,9 +254,7 @@ 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') {
 | 
				
			||||||
 | 
				
			|||||||
@ -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,
 | 
				
			||||||
 | 
				
			|||||||
@ -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) {
 | 
				
			||||||
 | 
					                // 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
 | 
					            while (currentChild !== null) {
 | 
				
			||||||
            let lastChild = dom.lastChild
 | 
					              let tmp = currentChild.nextSibling
 | 
				
			||||||
            while (lastChild !== null) {
 | 
					              dom.removeChild(currentChild)
 | 
				
			||||||
              dom.removeChild(lastChild)
 | 
					              currentChild = tmp
 | 
				
			||||||
              lastChild = dom.lastChild
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // insert fragment of undeleted nodes
 | 
					 | 
				
			||||||
            dom.appendChild(fragment)
 | 
					 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        /* TODO: smartscrolling
 | 
					        /* TODO: smartscrolling
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user