Sfoglia il codice sorgente

Merge pull request #127 from ckeditor/t/ckeditor5/1636

Other: Attach `'indentList'` and `'outdentList'` commands to `'indent'` and `'outdent'` commands.
The `@ckeditor/ckeditor5-indent` feature introduces the "indent" and "outdent" buttons which can be used to manipulate lists and other blocks.
Piotrek Koszuliński 6 anni fa
parent
commit
cef72898a6

+ 17 - 2
packages/ckeditor5-list/src/listediting.js

@@ -168,8 +168,23 @@ export default class ListEditing extends Plugin {
 			};
 		};
 
-		this.editor.keystrokes.set( 'Tab', getCommandExecuter( 'indentList' ) );
-		this.editor.keystrokes.set( 'Shift+Tab', getCommandExecuter( 'outdentList' ) );
+		editor.keystrokes.set( 'Tab', getCommandExecuter( 'indentList' ) );
+		editor.keystrokes.set( 'Shift+Tab', getCommandExecuter( 'outdentList' ) );
+	}
+
+	afterInit() {
+		const commands = this.editor.commands;
+
+		const indent = commands.get( 'indent' );
+		const outdent = commands.get( 'outdent' );
+
+		if ( indent ) {
+			indent.registerChildCommand( commands.get( 'indentList' ) );
+		}
+
+		if ( outdent ) {
+			outdent.registerChildCommand( commands.get( 'outdentList' ) );
+		}
 	}
 }
 

+ 56 - 0
packages/ckeditor5-list/tests/listediting.js

@@ -5,6 +5,7 @@
 
 import ListEditing from '../src/listediting';
 import ListCommand from '../src/listcommand';
+import IndentCommand from '../src/indentcommand';
 
 import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
 
@@ -17,6 +18,7 @@ import HeadingEditing from '@ckeditor/ckeditor5-heading/src/headingediting';
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 import { getData as getModelData, parse as parseModel, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { getData as getViewData, parse as parseView } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
+import IndentEditing from '@ckeditor/ckeditor5-indent/src/indentediting';
 
 import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
@@ -79,6 +81,60 @@ describe( 'ListEditing', () => {
 			expect( command ).to.be.instanceOf( ListCommand );
 			expect( command ).to.have.property( 'type', 'numbered' );
 		} );
+
+		it( 'should register indent list command', () => {
+			const command = editor.commands.get( 'indentList' );
+
+			expect( command ).to.be.instanceOf( IndentCommand );
+		} );
+
+		it( 'should register outdent list command', () => {
+			const command = editor.commands.get( 'outdentList' );
+
+			expect( command ).to.be.instanceOf( IndentCommand );
+		} );
+
+		it( 'should add indent list command to indent command', () => {
+			return VirtualTestEditor
+				.create( {
+					plugins: [ ListEditing, IndentEditing ]
+				} )
+				.then( newEditor => {
+					editor = newEditor;
+				} )
+				.then( () => {
+					const indentListCommand = editor.commands.get( 'indentList' );
+					const indentCommand = editor.commands.get( 'indent' );
+
+					const spy = sinon.spy( indentListCommand, 'execute' );
+
+					indentListCommand.isEnabled = true;
+					indentCommand.execute();
+
+					sinon.assert.calledOnce( spy );
+				} );
+		} );
+
+		it( 'should add outdent list command to outdent command', () => {
+			return VirtualTestEditor
+				.create( {
+					plugins: [ ListEditing, IndentEditing ]
+				} )
+				.then( newEditor => {
+					editor = newEditor;
+				} )
+				.then( () => {
+					const outdentListCommand = editor.commands.get( 'outdentList' );
+					const outdentCommand = editor.commands.get( 'outdent' );
+
+					const spy = sinon.spy( outdentListCommand, 'execute' );
+
+					outdentListCommand.isEnabled = true;
+					outdentCommand.execute();
+
+					sinon.assert.calledOnce( spy );
+				} );
+		} );
 	} );
 
 	describe( 'enter key handling callback', () => {