From bc94b5c032790eee1726973a0c508bcbb72e55c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Mon, 30 Mar 2020 16:08:34 +0200 Subject: [PATCH] Do not fix graveyard range if it would intersect with existing selection. --- src/model/documentselection.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/model/documentselection.js b/src/model/documentselection.js index 0ebf2f1aa..947d1fd69 100644 --- a/src/model/documentselection.js +++ b/src/model/documentselection.js @@ -1137,7 +1137,7 @@ class LiveSelection extends Selection { liveRange.detach(); // If nearest valid selection range has been found - add it in the place of old range. - if ( selectionRange ) { + if ( selectionRange && !isIntersecting( this._ranges, selectionRange ) ) { // Check the range, convert it to live range, bind events, etc. const newRange = this._prepareRange( selectionRange ); @@ -1190,3 +1190,15 @@ function clearAttributesStoredInElement( model, batch ) { } } } + +// Checks if range intersects with any given ranges. +function isIntersecting( ranges, selectionRange ) { + for ( let i = 0; i < ranges.length; i++ ) { + if ( selectionRange.isIntersecting( ranges[ i ] ) ) { + // It is also fine - as we can have multiple ranges in the selection. + return true; + } + } + + return false; +}