|
@@ -184,7 +184,8 @@ export default class Differ {
|
|
|
case 'changeAttribute': {
|
|
case 'changeAttribute': {
|
|
|
for ( const item of operation.range.getItems( { shallow: true } ) ) {
|
|
for ( const item of operation.range.getItems( { shallow: true } ) ) {
|
|
|
// Attribute change on refreshed element is ignored
|
|
// Attribute change on refreshed element is ignored
|
|
|
- if ( this._isInInsertedElement( item.parent ) || this._isInRefreshedElement( item ) ) {
|
|
|
|
|
|
|
+ // TODO: this is wrong if attribute would be handled elsewhere: || this._isInRefreshedElement( item )
|
|
|
|
|
+ if ( this._isInInsertedElement( item.parent ) ) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -447,6 +448,9 @@ export default class Differ {
|
|
|
let i = 0; // Iterator in `elementChildren` array -- iterates through current children of element.
|
|
let i = 0; // Iterator in `elementChildren` array -- iterates through current children of element.
|
|
|
let j = 0; // Iterator in `snapshotChildren` array -- iterates through old children of element.
|
|
let j = 0; // Iterator in `snapshotChildren` array -- iterates through old children of element.
|
|
|
|
|
|
|
|
|
|
+ // console.log( changes.map( change => change.type ) );
|
|
|
|
|
+ // console.log( 'actions', actions, elementChildren.length );
|
|
|
|
|
+
|
|
|
// Process every action.
|
|
// Process every action.
|
|
|
for ( const action of actions ) {
|
|
for ( const action of actions ) {
|
|
|
if ( action === 'i' ) {
|
|
if ( action === 'i' ) {
|
|
@@ -731,6 +735,10 @@ export default class Differ {
|
|
|
const incEnd = inc.offset + inc.howMany;
|
|
const incEnd = inc.offset + inc.howMany;
|
|
|
const oldEnd = old.offset + old.howMany;
|
|
const oldEnd = old.offset + old.howMany;
|
|
|
|
|
|
|
|
|
|
+ // if ( changes.length > 100 ) {
|
|
|
|
|
+ // debugger;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
if ( inc.type == 'insert' ) {
|
|
if ( inc.type == 'insert' ) {
|
|
|
if ( old.type == 'insert' ) {
|
|
if ( old.type == 'insert' ) {
|
|
|
if ( inc.offset <= old.offset ) {
|
|
if ( inc.offset <= old.offset ) {
|
|
@@ -775,6 +783,10 @@ export default class Differ {
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ //
|
|
|
|
|
+ // if ( old.type == 'refresh' ) {
|
|
|
|
|
+ // // console.log( '... old refresh, incoming insert' );
|
|
|
|
|
+ // }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if ( inc.type == 'remove' ) {
|
|
if ( inc.type == 'remove' ) {
|
|
@@ -832,18 +844,20 @@ export default class Differ {
|
|
|
// Attribute change needs to be split.
|
|
// Attribute change needs to be split.
|
|
|
const howMany = old.howMany;
|
|
const howMany = old.howMany;
|
|
|
|
|
|
|
|
- old.howMany = inc.offset - old.offset;
|
|
|
|
|
|
|
+ // old.howMany = inc.offset - old.offset;
|
|
|
|
|
|
|
|
const howManyAfter = howMany - old.howMany - inc.nodesToHandle;
|
|
const howManyAfter = howMany - old.howMany - inc.nodesToHandle;
|
|
|
|
|
|
|
|
- // Add the second part of attribute change to the beginning of processed array so it won't
|
|
|
|
|
- // be processed again in this loop.
|
|
|
|
|
- changes.unshift( {
|
|
|
|
|
- type: 'attribute',
|
|
|
|
|
- offset: inc.offset,
|
|
|
|
|
- howMany: howManyAfter,
|
|
|
|
|
- count: this._changeCount++
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ if ( howManyAfter > 0 ) {
|
|
|
|
|
+ // Add the second part of attribute change to the beginning of processed array so it won't
|
|
|
|
|
+ // be processed again in this loop.
|
|
|
|
|
+ changes.unshift( {
|
|
|
|
|
+ type: 'attribute',
|
|
|
|
|
+ offset: inc.offset,
|
|
|
|
|
+ howMany: howManyAfter,
|
|
|
|
|
+ count: this._changeCount++
|
|
|
|
|
+ } );
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
old.howMany -= oldEnd - inc.offset;
|
|
old.howMany -= oldEnd - inc.offset;
|
|
|
}
|
|
}
|
|
@@ -919,6 +933,22 @@ export default class Differ {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if ( inc.type == 'refresh' ) {
|
|
|
|
|
+ if ( old.type == 'insert' ) {
|
|
|
|
|
+ if ( inc.offset === old.offset && inc.howMany === old.howMany ) {
|
|
|
|
|
+ // console.log( '... old INSERT, incoming REFRESH --- HANDLED!' );
|
|
|
|
|
+ old.howMany = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ( old.type == 'remove' ) {
|
|
|
|
|
+ if ( inc.offset === old.offset && inc.howMany === old.howMany ) {
|
|
|
|
|
+ // console.log( '... old REMOVE, incoming REFRESH --- HANDLED!' );
|
|
|
|
|
+ inc.nodesToHandle = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inc.howMany = inc.nodesToHandle;
|
|
inc.howMany = inc.nodesToHandle;
|
|
@@ -1202,6 +1232,7 @@ function _generateActionsFromChanges( oldChildrenLength, changes ) {
|
|
|
|
|
|
|
|
// Then, fill up actions accordingly to change type.
|
|
// Then, fill up actions accordingly to change type.
|
|
|
if ( change.type == 'insert' ) {
|
|
if ( change.type == 'insert' ) {
|
|
|
|
|
+ // console.log( 'change type of INSERT', change.offset, change.howMany );
|
|
|
for ( let i = 0; i < change.howMany; i++ ) {
|
|
for ( let i = 0; i < change.howMany; i++ ) {
|
|
|
actions.push( 'i' );
|
|
actions.push( 'i' );
|
|
|
}
|
|
}
|
|
@@ -1225,6 +1256,7 @@ function _generateActionsFromChanges( oldChildrenLength, changes ) {
|
|
|
// We changed `howMany` old nodes, update `oldChildrenHandled`.
|
|
// We changed `howMany` old nodes, update `oldChildrenHandled`.
|
|
|
oldChildrenHandled += change.howMany;
|
|
oldChildrenHandled += change.howMany;
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ // console.log( 'change type of REFRESH', change.offset, change.howMany );
|
|
|
actions.push( 'x' );
|
|
actions.push( 'x' );
|
|
|
|
|
|
|
|
// The last handled offset is after inserted range.
|
|
// The last handled offset is after inserted range.
|
|
@@ -1240,6 +1272,8 @@ function _generateActionsFromChanges( oldChildrenLength, changes ) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // console.log( 'Changes', Array.from( changes ).map( change => change.type ), 'actions', actions );
|
|
|
|
|
+
|
|
|
return actions;
|
|
return actions;
|
|
|
}
|
|
}
|
|
|
|
|
|