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

Internal (autoformat): Added support for making lists, code block and block quote for a non-empty blocks.

Marek Lewandowski 5 лет назад
Родитель
Сommit
babd0fd088

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

@@ -51,11 +51,11 @@ export default class Autoformat extends Plugin {
 		const commands = this.editor.commands;
 		const commands = this.editor.commands;
 
 
 		if ( commands.get( 'bulletedList' ) ) {
 		if ( commands.get( 'bulletedList' ) ) {
-			blockAutoformatEditing( this.editor, this, /^[*-]\s$/, 'bulletedList' );
+			blockAutoformatEditing( this.editor, this, /^[*-]\s/, 'bulletedList' );
 		}
 		}
 
 
 		if ( commands.get( 'numberedList' ) ) {
 		if ( commands.get( 'numberedList' ) ) {
-			blockAutoformatEditing( this.editor, this, /^1[.|)]\s$/, 'numberedList' );
+			blockAutoformatEditing( this.editor, this, /^1[.|)]\s/, 'numberedList' );
 		}
 		}
 	}
 	}
 
 
@@ -148,7 +148,7 @@ export default class Autoformat extends Plugin {
 	 */
 	 */
 	_addBlockQuoteAutoformats() {
 	_addBlockQuoteAutoformats() {
 		if ( this.editor.commands.get( 'blockQuote' ) ) {
 		if ( this.editor.commands.get( 'blockQuote' ) ) {
-			blockAutoformatEditing( this.editor, this, /^>\s$/, 'blockQuote' );
+			blockAutoformatEditing( this.editor, this, /^>\s/, 'blockQuote' );
 		}
 		}
 	}
 	}
 
 
@@ -162,7 +162,7 @@ export default class Autoformat extends Plugin {
 	 */
 	 */
 	_addCodeBlockAutoformats() {
 	_addCodeBlockAutoformats() {
 		if ( this.editor.commands.get( 'codeBlock' ) ) {
 		if ( this.editor.commands.get( 'codeBlock' ) ) {
-			blockAutoformatEditing( this.editor, this, /^```$/, 'codeBlock' );
+			blockAutoformatEditing( this.editor, this, /^```/, 'codeBlock' );
 		}
 		}
 	}
 	}
 }
 }

+ 36 - 0
packages/ckeditor5-autoformat/tests/autoformat.js

@@ -77,6 +77,15 @@ describe( 'Autoformat', () => {
 			expect( getData( model ) ).to.equal( '<listItem listIndent="0" listType="bulleted">[]</listItem>' );
 			expect( getData( model ) ).to.equal( '<listItem listIndent="0" listType="bulleted">[]</listItem>' );
 		} );
 		} );
 
 
+		it( 'should replace a non-empty paragraph using the parenthesis format', () => {
+			setData( model, '<paragraph>*[]sample text</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
+			} );
+
+			expect( getData( model ) ).to.equal( '<listItem listIndent="0" listType="bulleted">[]sample text</listItem>' );
+		} );
+
 		it( 'should not replace minus character when inside bulleted list item', () => {
 		it( 'should not replace minus character when inside bulleted list item', () => {
 			setData( model, '<listItem listIndent="0" listType="bulleted">-[]</listItem>' );
 			setData( model, '<listItem listIndent="0" listType="bulleted">-[]</listItem>' );
 			model.change( writer => {
 			model.change( writer => {
@@ -115,6 +124,15 @@ describe( 'Autoformat', () => {
 			expect( getData( model ) ).to.equal( '<listItem listIndent="0" listType="numbered">[]</listItem>' );
 			expect( getData( model ) ).to.equal( '<listItem listIndent="0" listType="numbered">[]</listItem>' );
 		} );
 		} );
 
 
+		it( 'should replace a non-empty paragraph using the parenthesis format', () => {
+			setData( model, '<paragraph>1)[]sample text</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
+			} );
+
+			expect( getData( model ) ).to.equal( '<listItem listIndent="0" listType="numbered">[]sample text</listItem>' );
+		} );
+
 		it( 'should not replace digit character when there is no . or ) in the format', () => {
 		it( 'should not replace digit character when there is no . or ) in the format', () => {
 			setData( model, '<paragraph>1[]</paragraph>' );
 			setData( model, '<paragraph>1[]</paragraph>' );
 			model.change( writer => {
 			model.change( writer => {
@@ -282,6 +300,15 @@ describe( 'Autoformat', () => {
 			expect( getData( model ) ).to.equal( '<blockQuote><paragraph>[]</paragraph></blockQuote>' );
 			expect( getData( model ) ).to.equal( '<blockQuote><paragraph>[]</paragraph></blockQuote>' );
 		} );
 		} );
 
 
+		it( 'should replace greater-than character in a non-empty paragraph', () => {
+			setData( model, '<paragraph>>[]foo</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
+			} );
+
+			expect( getData( model ) ).to.equal( '<blockQuote><paragraph>[]foo</paragraph></blockQuote>' );
+		} );
+
 		it( 'should wrap the heading if greater-than character was used', () => {
 		it( 'should wrap the heading if greater-than character was used', () => {
 			setData( model, '<heading1>>[]</heading1>' );
 			setData( model, '<heading1>>[]</heading1>' );
 			model.change( writer => {
 			model.change( writer => {
@@ -338,6 +365,15 @@ describe( 'Autoformat', () => {
 			expect( getData( model ) ).to.equal( '<codeBlock language="plaintext">[]</codeBlock>' );
 			expect( getData( model ) ).to.equal( '<codeBlock language="plaintext">[]</codeBlock>' );
 		} );
 		} );
 
 
+		it( 'should replace triple grave accents in a non-empty paragraph', () => {
+			setData( model, '<paragraph>``[]let foo = 1;</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '`', doc.selection.getFirstPosition() );
+			} );
+
+			expect( getData( model ) ).to.equal( '<codeBlock language="plaintext">[]let foo = 1;</codeBlock>' );
+		} );
+
 		it( 'should not replace triple grave accents when already in a code block', () => {
 		it( 'should not replace triple grave accents when already in a code block', () => {
 			setData( model, '<codeBlock language="plaintext">``[]</codeBlock>' );
 			setData( model, '<codeBlock language="plaintext">``[]</codeBlock>' );
 			model.change( writer => {
 			model.change( writer => {