Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Changed: implementation of view/model.Selection#isEqual.
Browse files Browse the repository at this point in the history
  • Loading branch information
scofalik committed Nov 16, 2016
1 parent b1e0e1f commit 9a10e12
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
27 changes: 19 additions & 8 deletions src/model/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,25 @@ export default class Selection {
return false;
}

// Every range from this selection...
return Array.from( this.getRanges() ).every( ( rangeA ) => {
// ... has a range in other selection...
return Array.from( otherSelection.getRanges() ).some( ( rangeB ) => {
// ... which it is equal to.
return rangeA.isEqual( rangeB );
} );
} );
const thisRanges = Array.from( this.getRanges() );
const otherRanges = Array.from( otherSelection.getRanges() );

for ( let thisRange of thisRanges ) {
let found = false;

for ( let otherRange of otherRanges ) {
if ( thisRange.isEqual( otherRange ) ) {
found = true;
break;
}
}

if ( !found ) {
return false;
}
}

return true;
}

/**
Expand Down
27 changes: 19 additions & 8 deletions src/view/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,25 @@ export default class Selection {
return false;
}

// Every range from this selection...
return Array.from( this.getRanges() ).every( ( rangeA ) => {
// ... has a range in other selection...
return Array.from( otherSelection.getRanges() ).some( ( rangeB ) => {
// ... which it is equal to.
return rangeA.isEqual( rangeB );
} );
} );
const thisRanges = Array.from( this.getRanges() );
const otherRanges = Array.from( otherSelection.getRanges() );

for ( let thisRange of thisRanges ) {
let found = false;

for ( let otherRange of otherRanges ) {
if ( thisRange.isEqual( otherRange ) ) {
found = true;
break;
}
}

if ( !found ) {
return false;
}
}

return true;
}

/**
Expand Down

0 comments on commit 9a10e12

Please sign in to comment.