8
0
Pārlūkot izejas kodu

Fixed inline autoformatting regexp and the way text is obtained from selection parent element.

Szymon Kupś 9 gadi atpakaļ
vecāks
revīzija
9077004b16

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

@@ -81,9 +81,9 @@ export default class Autoformat extends Feature {
 	 * @private
 	 */
 	_addInlineAutoformats() {
-		new InlineAutoformatEngine( this.editor, /(\*\*)([^\*]+?)(\*\*)$/g, 'bold' );
-		new InlineAutoformatEngine( this.editor, /(__)([^_]+?)(__)$/g, 'bold' );
-		new InlineAutoformatEngine( this.editor, /(?:^|[^\*])(\*)([^\*_]+?)(\*)$/g, 'italic' );
-		new InlineAutoformatEngine( this.editor, /(?:^|[^_])(_)([^_]+?)(_)$/g, 'italic' );
+		new InlineAutoformatEngine( this.editor, /(\*\*)([^\*]+)(\*\*)$/g, 'bold' );
+		new InlineAutoformatEngine( this.editor, /(__)([^_]+)(__)$/g, 'bold' );
+		new InlineAutoformatEngine( this.editor, /(?:^|[^\*])(\*)([^\*_]+)(\*)$/g, 'italic' );
+		new InlineAutoformatEngine( this.editor, /(?:^|[^_])(_)([^_]+)(_)$/g, 'italic' );
 	}
 }

+ 2 - 14
packages/ckeditor5-autoformat/src/inlineautoformatengine.js

@@ -4,7 +4,6 @@
  */
 
 import LiveRange from '../engine/model/liverange.js';
-import Text from '../engine/model/text.js';
 import getSchemaValidRanges from '../core/command/helpers/getschemavalidranges.js';
 
 /**
@@ -193,22 +192,11 @@ export default class InlineAutoformatEngine {
 	}
 }
 
-// Returns whole text from parent element by adding all data from text nodes together. If one of the children is not
-// an instance of {@link engine.model.Text} function will return an empty string.
+// Returns whole text from parent element by adding all data from text nodes together.
 //
 // @private
 // @param {engine.model.Element} element
 // @returns {String}
 function getText( element ) {
-	let text = '';
-
-	for ( let child of element.getChildren() ) {
-		if ( child instanceof Text ) {
-			text += child.data;
-		} else {
-			return '';
-		}
-	}
-
-	return text;
+	return Array.from( element.getChildren() ).reduce( ( a, b ) => a + b.data, '' );
 }

+ 0 - 12
packages/ckeditor5-autoformat/tests/inlineautoformatengine.js

@@ -60,18 +60,6 @@ describe( 'InlineAutoformatEngine', () => {
 
 			expect( getData( doc ) ).to.equal( '<paragraph>*foob[*ar]</paragraph>' );
 		} );
-
-		it( 'should stop early if there are block elements in the way', () => {
-			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, 'testAttribute' );
-			doc.schema.registerItem( 'widget', '$block' );
-
-			setData( doc, '<paragraph>*foo<paragraph>baz</paragraph>bar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insert( doc.selection.getFirstPosition(), '*' );
-			} );
-
-			expect( getData( doc ) ).to.equal( '<paragraph>*foo<paragraph>baz</paragraph>bar*[]</paragraph>' );
-		} );
 	} );
 
 	describe( 'Callback', () => {