8
0
Просмотр исходного кода

Fixed restoring selection on undo for cases when transformed ranges are interleaved by ranges in graveyard.

Kuba Niegowski 5 лет назад
Родитель
Сommit
32cf59a73f
1 измененных файлов с 10 добавлено и 11 удалено
  1. 10 11
      packages/ckeditor5-undo/src/basecommand.js

+ 10 - 11
packages/ckeditor5-undo/src/basecommand.js

@@ -100,7 +100,14 @@ export default class BaseCommand extends Command {
 
 
 		for ( const rangeGroup of transformedRangeGroups ) {
 		for ( const rangeGroup of transformedRangeGroups ) {
 			// While transforming there could appear ranges that are contained by other ranges, we shall ignore them.
 			// While transforming there could appear ranges that are contained by other ranges, we shall ignore them.
-			const transformed = rangeGroup.filter( range => !isRangeContainedByAnyOtherRange( range, allRanges ) );
+			const transformed = rangeGroup
+				.filter( range => range.root != document.graveyard )
+				.filter( range => !isRangeContainedByAnyOtherRange( range, allRanges ) );
+
+			// All the transformed ranges ended up in graveyard.
+			if ( !transformed.length ) {
+				continue;
+			}
 
 
 			// After the range got transformed, we have an array of ranges. Some of those
 			// After the range got transformed, we have an array of ranges. Some of those
 			// ranges may be "touching" -- they can be next to each other and could be merged.
 			// ranges may be "touching" -- they can be next to each other and could be merged.
@@ -108,16 +115,8 @@ export default class BaseCommand extends Command {
 
 
 			// For each `range` from `ranges`, we take only one transformed range.
 			// For each `range` from `ranges`, we take only one transformed range.
 			// This is because we want to prevent situation where single-range selection
 			// This is because we want to prevent situation where single-range selection
-			// got transformed to multi-range selection. We will take the first range that
-			// is not in the graveyard.
-			const newRange = transformed.find(
-				range => range.root != document.graveyard
-			);
-
-			// `transformedRange` might be `undefined` if transformed range ended up in graveyard.
-			if ( newRange ) {
-				selectionRanges.push( newRange );
-			}
+			// got transformed to multi-range selection.
+			selectionRanges.push( transformed[ 0 ] );
 		}
 		}
 
 
 		// @if CK_DEBUG_ENGINE // console.log( `Restored selection by undo: ${ selectionRanges.join( ', ' ) }` );
 		// @if CK_DEBUG_ENGINE // console.log( `Restored selection by undo: ${ selectionRanges.join( ', ' ) }` );