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

Fixed: `modelChangePostFixer` works correctly when item is moved out of container.

Szymon Cofalik 8 лет назад
Родитель
Сommit
513d962ce1

+ 11 - 4
packages/ckeditor5-list/src/converters.js

@@ -574,18 +574,25 @@ export function modelChangePostFixer( document ) {
 			return;
 		}
 
+		let sourcePos;
+
+		if ( changes.sourcePosition ) {
+			const howMany = changes.range.end.offset - changes.range.start.offset;
+			sourcePos = changes.sourcePosition._getTransformedByInsertion( changes.range.start, howMany, true );
+		}
+
 		if ( type == 'remove' ) {
 			// Fix list items after the cut-out range.
 			// This fix is needed if items in model after cut-out range have now wrong indents compared to their previous siblings.
-			_fixItemsIndent( changes.sourcePosition, document, batch );
+			_fixItemsIndent( sourcePos, document, batch );
 			// This fix is needed if two different nested lists got merged, change types of list items "below".
-			_fixItemsType( changes.sourcePosition, false, document, batch );
+			_fixItemsType( sourcePos, false, document, batch );
 		} else if ( type == 'move' ) {
 			// Fix list items after the cut-out range.
 			// This fix is needed if items in model after cut-out range have now wrong indents compared to their previous siblings.
-			_fixItemsIndent( changes.sourcePosition, document, batch );
+			_fixItemsIndent( sourcePos, document, batch );
 			// This fix is needed if two different nested lists got merged, change types of list items "below".
-			_fixItemsType( changes.sourcePosition, false, document, batch );
+			_fixItemsType( sourcePos, false, document, batch );
 
 			// Fix items in moved range.
 			// This fix is needed if inserted items are too deeply intended.

+ 25 - 1
packages/ckeditor5-list/tests/listengine.js

@@ -17,6 +17,7 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import BoldEngine from '@ckeditor/ckeditor5-basic-styles/src/boldengine';
 import UndoEngine from '@ckeditor/ckeditor5-undo/src/undoengine';
 import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
+import BlockQuoteEngine from '@ckeditor/ckeditor5-block-quote/src/blockquoteengine';
 
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 import { getData as getModelData, setData as setModelData, parse as parseModel } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
@@ -28,7 +29,7 @@ describe( 'ListEngine', () => {
 	beforeEach( () => {
 		return VirtualTestEditor
 			.create( {
-				plugins: [ Clipboard, BoldEngine, Paragraph, ListEngine, UndoEngine ]
+				plugins: [ Clipboard, BoldEngine, Paragraph, ListEngine, UndoEngine, BlockQuoteEngine ]
 			} )
 			.then( newEditor => {
 				editor = newEditor;
@@ -2999,6 +3000,29 @@ describe( 'ListEngine', () => {
 				'<listItem indent="1" type="bulleted">e</listItem>' +
 				'<listItem indent="1" type="bulleted">i</listItem>'
 			);
+
+			// #78.
+			test(
+				'move out of container',
+
+				'<blockQuote>' +
+					'<listItem indent="0" type="bulleted">a</listItem>' +
+					'<listItem indent="1" type="bulleted">b</listItem>' +
+					'<listItem indent="1" type="bulleted">c</listItem>' +
+					'<listItem indent="1" type="bulleted">d</listItem>' +
+					'[<listItem indent="2" type="bulleted">e</listItem>]' +
+				'</blockQuote>',
+
+				0,
+
+				'<listItem indent="0" type="bulleted">e</listItem>' +
+				'<blockQuote>' +
+					'<listItem indent="0" type="bulleted">a</listItem>' +
+					'<listItem indent="1" type="bulleted">b</listItem>' +
+					'<listItem indent="1" type="bulleted">c</listItem>' +
+					'<listItem indent="1" type="bulleted">d</listItem>' +
+				'</blockQuote>'
+			);
 		} );
 
 		describe( 'rename', () => {