diff --git a/src/model/differ.js b/src/model/differ.js index ddb2b7cac..aa881a877 100644 --- a/src/model/differ.js +++ b/src/model/differ.js @@ -292,6 +292,23 @@ export default class Differ { return result; } + /** + * Returns all markers which changed. + * + * @returns {Array.} + */ + getChangedMarkers() { + return Array.from( this._changedMarkers ).map( item => ( + { + name: item[ 0 ], + data: { + oldRange: item[ 1 ].oldRange, + newRange: item[ 1 ].newRange + } + } + ) ); + } + /** * Checks whether some of the buffered changes affect the editor data. * diff --git a/tests/model/differ.js b/tests/model/differ.js index e0c103374..505251afa 100644 --- a/tests/model/differ.js +++ b/tests/model/differ.js @@ -1403,6 +1403,16 @@ describe( 'Differ', () => { expect( differ.getMarkersToAdd() ).to.deep.equal( [ { name: 'name', range } ] ); + + expect( differ.getChangedMarkers() ).to.deep.equal( [ + { + name: 'name', + data: { + oldRange: null, + newRange: range + } + } + ] ); } ); it( 'remove marker', () => { @@ -1413,6 +1423,16 @@ describe( 'Differ', () => { ] ); expect( differ.getMarkersToAdd() ).to.deep.equal( [] ); + + expect( differ.getChangedMarkers() ).to.deep.equal( [ + { + name: 'name', + data: { + oldRange: range, + newRange: null + } + } + ] ); } ); it( 'change marker\'s range', () => { @@ -1425,6 +1445,16 @@ describe( 'Differ', () => { expect( differ.getMarkersToAdd() ).to.deep.equal( [ { name: 'name', range: rangeB } ] ); + + expect( differ.getChangedMarkers() ).to.deep.equal( [ + { + name: 'name', + data: { + oldRange: range, + newRange: rangeB + } + } + ] ); } ); it( 'add marker not affecting data', () => { @@ -1445,6 +1475,8 @@ describe( 'Differ', () => { expect( differ.getMarkersToRemove() ).to.deep.equal( [] ); expect( differ.getMarkersToAdd() ).to.deep.equal( [] ); + expect( differ.getChangedMarkers() ).to.deep.equal( [] ); + expect( differ.hasDataChanges() ).to.be.false; } ); @@ -1457,6 +1489,16 @@ describe( 'Differ', () => { expect( differ.getMarkersToAdd() ).to.deep.equal( [ { name: 'name', range: rangeB } ] ); + + expect( differ.getChangedMarkers() ).to.deep.equal( [ + { + name: 'name', + data: { + oldRange: null, + newRange: rangeB + } + } + ] ); } ); it( 'change marker to not affecting data', () => { @@ -1475,6 +1517,17 @@ describe( 'Differ', () => { ] ); expect( differ.getMarkersToAdd() ).to.deep.equal( [] ); + + expect( differ.getChangedMarkers() ).to.deep.equal( [ + { + name: 'name', + data: { + oldRange: range, + newRange: null + } + } + ] ); + expect( differ.hasDataChanges() ).to.be.true; } ); @@ -1489,6 +1542,16 @@ describe( 'Differ', () => { expect( differ.getMarkersToAdd() ).to.deep.equal( [ { name: 'name', range } ] ); + + expect( differ.getChangedMarkers() ).to.deep.equal( [ + { + name: 'name', + data: { + oldRange: range, + newRange: range + } + } + ] ); } ); it( 'change marker to the same range', () => { @@ -1501,6 +1564,16 @@ describe( 'Differ', () => { expect( differ.getMarkersToAdd() ).to.deep.equal( [ { name: 'name', range } ] ); + + expect( differ.getChangedMarkers() ).to.deep.equal( [ + { + name: 'name', + data: { + oldRange: range, + newRange: range + } + } + ] ); } ); } );