Przeglądaj źródła

The single undo step will be created while selection was not anchored in a list.

Kamil Piechaczek 5 lat temu
rodzic
commit
311f3a25bc

+ 4 - 2
packages/ckeditor5-list/src/liststyleui.js

@@ -216,8 +216,10 @@ function getStyleButtonCreator( { editor, listStyleCommand, parentCommandName }
 			}
 			}
 			// If the content the selection is anchored to is not a list, let's create a list of a desired style.
 			// If the content the selection is anchored to is not a list, let's create a list of a desired style.
 			else {
 			else {
-				editor.execute( parentCommandName );
-				editor.execute( 'listStyle', { type } );
+				editor.model.change( () => {
+					editor.execute( parentCommandName );
+					editor.execute( 'listStyle', { type } );
+				} );
 			}
 			}
 
 
 			editor.editing.view.focus();
 			editor.editing.view.focus();

+ 37 - 2
packages/ckeditor5-list/tests/liststyleui.js

@@ -9,10 +9,11 @@ import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictest
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
 import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
 import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
 import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
-import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import ListStyle from '../src/liststyle';
 import ListStyle from '../src/liststyle';
 import ListStyleUI from '../src/liststyleui';
 import ListStyleUI from '../src/liststyleui';
 import DropdownView from '@ckeditor/ckeditor5-ui/src/dropdown/dropdownview';
 import DropdownView from '@ckeditor/ckeditor5-ui/src/dropdown/dropdownview';
+import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
 
 
 import bulletedListIcon from '../theme/icons/bulletedlist.svg';
 import bulletedListIcon from '../theme/icons/bulletedlist.svg';
 import numberedListIcon from '../theme/icons/numberedlist.svg';
 import numberedListIcon from '../theme/icons/numberedlist.svg';
@@ -34,7 +35,7 @@ describe( 'ListStyleUI', () => {
 		editorElement = document.createElement( 'div' );
 		editorElement = document.createElement( 'div' );
 		document.body.appendChild( editorElement );
 		document.body.appendChild( editorElement );
 
 
-		return ClassicTestEditor.create( editorElement, { plugins: [ Paragraph, BlockQuote, ListStyle ] } )
+		return ClassicTestEditor.create( editorElement, { plugins: [ Paragraph, BlockQuote, ListStyle, UndoEditing ] } )
 			.then( newEditor => {
 			.then( newEditor => {
 				editor = newEditor;
 				editor = newEditor;
 				model = editor.model;
 				model = editor.model;
@@ -230,10 +231,27 @@ describe( 'ListStyleUI', () => {
 
 
 						styleButtonView.fire( 'execute' );
 						styleButtonView.fire( 'execute' );
 
 
+						sinon.assert.calledWithExactly( editor.execute, 'bulletedList' );
 						sinon.assert.calledWithExactly( editor.execute, 'listStyle', { type: 'circle' } );
 						sinon.assert.calledWithExactly( editor.execute, 'listStyle', { type: 'circle' } );
 						sinon.assert.calledOnce( editor.editing.view.focus );
 						sinon.assert.calledOnce( editor.editing.view.focus );
 						sinon.assert.callOrder( editor.execute, editor.editing.view.focus );
 						sinon.assert.callOrder( editor.execute, editor.editing.view.focus );
 					} );
 					} );
+
+					it( 'should create the single undo step while selection was not anchored in a list', () => {
+						setData( model, '<paragraph>foo[]</paragraph>' );
+
+						styleButtonView.fire( 'execute' );
+
+						expect( getData( model ) ).to.equal(
+							'<listItem listIndent="0" listStyle="circle" listType="bulleted">foo[]</listItem>'
+						);
+
+						editor.execute( 'undo' );
+
+						expect( getData( model ) ).to.equal(
+							'<paragraph>foo[]</paragraph>'
+						);
+					} );
 				} );
 				} );
 			} );
 			} );
 		} );
 		} );
@@ -434,10 +452,27 @@ describe( 'ListStyleUI', () => {
 
 
 						styleButtonView.fire( 'execute' );
 						styleButtonView.fire( 'execute' );
 
 
+						sinon.assert.calledWithExactly( editor.execute, 'numberedList' );
 						sinon.assert.calledWithExactly( editor.execute, 'listStyle', { type: 'decimal-leading-zero' } );
 						sinon.assert.calledWithExactly( editor.execute, 'listStyle', { type: 'decimal-leading-zero' } );
 						sinon.assert.calledOnce( editor.editing.view.focus );
 						sinon.assert.calledOnce( editor.editing.view.focus );
 						sinon.assert.callOrder( editor.execute, editor.editing.view.focus );
 						sinon.assert.callOrder( editor.execute, editor.editing.view.focus );
 					} );
 					} );
+
+					it( 'should create the single undo step while selection was not anchored in a list', () => {
+						setData( model, '<paragraph>foo[]</paragraph>' );
+
+						styleButtonView.fire( 'execute' );
+
+						expect( getData( model ) ).to.equal(
+							'<listItem listIndent="0" listStyle="decimal-leading-zero" listType="numbered">foo[]</listItem>'
+						);
+
+						editor.execute( 'undo' );
+
+						expect( getData( model ) ).to.equal(
+							'<paragraph>foo[]</paragraph>'
+						);
+					} );
 				} );
 				} );
 			} );
 			} );
 		} );
 		} );