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

Started using engine's getSelectedBlocks().

Piotrek Koszuliński 9 лет назад
Родитель
Сommit
9cdf1581d9
2 измененных файлов с 3 добавлено и 48 удалено
  1. 2 2
      packages/ckeditor5-list/src/listcommand.js
  2. 1 46
      packages/ckeditor5-list/tests/utils.js

+ 2 - 2
packages/ckeditor5-list/src/listcommand.js

@@ -8,7 +8,7 @@
  */
 
 import Command from '@ckeditor/ckeditor5-core/src/command/command';
-import { getClosestListItem, getSelectedBlocks, getPositionBeforeBlock } from './utils';
+import { getClosestListItem, getPositionBeforeBlock } from './utils';
 
 /**
  * The list command. It is used by the {@link module:list/list~List list feature}.
@@ -72,7 +72,7 @@ export default class ListCommand extends Command {
 	 */
 	_doExecute( options = {} ) {
 		const document = this.editor.document;
-		const blocks = getSelectedBlocks( document.selection, document.schema );
+		const blocks = Array.from( document.selection.getSelectedBlocks() );
 
 		// Whether we are turning off some items.
 		const turnOff = this.value === true;

+ 1 - 46
packages/ckeditor5-list/tests/utils.js

@@ -3,13 +3,12 @@
  * For licensing, see LICENSE.md.
  */
 
-import { getClosestListItem, getSelectedBlocks, getPositionBeforeBlock } from '../src/utils';
+import { getClosestListItem, getPositionBeforeBlock } from '../src/utils';
 
 import Element from '@ckeditor/ckeditor5-engine/src/model/element';
 import Text from '@ckeditor/ckeditor5-engine/src/model/text';
 import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import Schema from '@ckeditor/ckeditor5-engine/src/model/schema';
-import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
 
 describe( 'getClosestListItem', () => {
 	const item = new Element( 'listItem', null, 'foobar' );
@@ -24,50 +23,6 @@ describe( 'getClosestListItem', () => {
 	} );
 } );
 
-describe( 'getSelectedBlocks', () => {
-	const paragraph1 = new Element( 'paragraph', null, '---' );
-	const item1 = new Element( 'listItem', null, '---' );
-	const item2 = new Element( 'listItem', null, '---' );
-	const item3 = new Element( 'listItem', null, '---' );
-	const paragraph2 = new Element( 'paragraph', null, '---' );
-
-	const root = new Element( '$root', null, [
-		paragraph1, item1, item2, item3, paragraph2
-	] );
-
-	const schema = new Schema();
-	schema.registerItem( 'paragraph', '$block' );
-	schema.registerItem( 'listItem', '$block' );
-
-	const selection = new Selection();
-
-	it( 'should return just one block if selection is over one block', () => {
-		selection.collapse( root, 2 );
-		selection.setFocus( root, 3 );
-
-		expect( getSelectedBlocks( selection, schema ) ).to.deep.equal( [ item2 ] );
-	} );
-
-	it( 'should return ancestor block if selection is collapsed and not before a block', () => {
-		selection.collapse( paragraph1, 2 );
-
-		expect( getSelectedBlocks( selection, schema ) ).to.deep.equal( [ paragraph1 ] );
-	} );
-
-	it( 'should return empty array for collapsed selection before a block, in a root', () => {
-		selection.collapse( root, 1 );
-
-		expect( getSelectedBlocks( selection, schema ) ).to.deep.equal( [] );
-	} );
-
-	it( 'should return all blocks "touched" by the selection if it spans over multiple blocks', () => {
-		selection.collapse( item1, 3 );
-		selection.setFocus( root, 4 );
-
-		expect( getSelectedBlocks( selection, schema ) ).to.deep.equal( [ item1, item2, item3 ] );
-	} );
-} );
-
 describe( 'getPositionBeforeBlock', () => {
 	const paragraph = new Element( 'paragraph', null, 'foo' );
 	const item = new Element( 'listItem', null, 'bar' );