Ver Fonte

Fix: Autoformat regex in numbered lists. Closes #42.

vladikoff há 8 anos atrás
pai
commit
ed2825f7ce

+ 1 - 1
packages/ckeditor5-autoformat/src/autoformat.js

@@ -54,7 +54,7 @@ export default class Autoformat extends Plugin {
 
 		if ( commands.get( 'numberedList' ) ) {
 			// eslint-disable-next-line no-new
-			new BlockAutoformatEngine( this.editor, /^\d+[.|)]?\s$/, 'numberedList' );
+			new BlockAutoformatEngine( this.editor, /^\d+[.|)]\s$/, 'numberedList' );
 		}
 	}
 

+ 19 - 1
packages/ckeditor5-autoformat/tests/autoformat.js

@@ -82,7 +82,7 @@ describe( 'Autoformat', () => {
 	} );
 
 	describe( 'Numbered list', () => {
-		it( 'should replace digit with numbered list item', () => {
+		it( 'should replace digit with numbered list item using the dot format', () => {
 			setData( doc, '<paragraph>1.[]</paragraph>' );
 			doc.enqueueChanges( () => {
 				batch.insert( doc.selection.getFirstPosition(), ' ' );
@@ -91,6 +91,24 @@ describe( 'Autoformat', () => {
 			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
 		} );
 
+		it( 'should replace digit with numbered list item using the parenthesis format', () => {
+			setData( doc, '<paragraph>1)[]</paragraph>' );
+			doc.enqueueChanges( () => {
+				batch.insert( doc.selection.getFirstPosition(), ' ' );
+			} );
+
+			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
+		} );
+
+		it( 'should not replace digit character when there is no . or ) in the format', () => {
+			setData( doc, '<paragraph>1[]</paragraph>' );
+			doc.enqueueChanges( () => {
+				batch.insert( doc.selection.getFirstPosition(), ' ' );
+			} );
+
+			expect( getData( doc ) ).to.equal( '<paragraph>1 []</paragraph>' );
+		} );
+
 		it( 'should not replace digit character when inside numbered list item', () => {
 			setData( doc, '<listItem indent="0" type="numbered">1.[]</listItem>' );
 			doc.enqueueChanges( () => {