Browse Source

Fixed leaky IndentCommand state check.

Piotrek Koszuliński 8 years ago
parent
commit
ba9269cd8f

+ 1 - 1
packages/ckeditor5-list/src/indentcommand.js

@@ -116,7 +116,7 @@ export default class IndentCommand extends Command {
 		const listItem = first( this.editor.document.selection.getSelectedBlocks() );
 
 		// If selection is not in a list item, the command is disabled.
-		if ( !listItem ) {
+		if ( !listItem || !listItem.is( 'listItem' ) ) {
 			return false;
 		}
 

+ 9 - 0
packages/ckeditor5-list/tests/indentcommand.js

@@ -68,6 +68,15 @@ describe( 'IndentCommand', () => {
 
 				expect( command.isEnabled ).to.be.false;
 			} );
+
+			// Edge case but may happen that some other blocks will also use the indent attribute
+			// and before we fixed it the command was enabled in such a case.
+			it( 'should be false if selection starts in a paragraph with indent attribute', () => {
+				doc.schema.allow( { name: 'paragraph', attributes: [ 'indent' ], inside: '$root' } );
+				setData( doc, '<listItem indent="0">a</listItem><paragraph indent="0">b[]</paragraph>' );
+
+				expect( command.isEnabled ).to.be.false;
+			} );
 		} );
 
 		describe( '_doExecute', () => {