Forráskód Böngészése

Merge pull request #15 from ckeditor/t/14

Fixed wrong text slicing during inline autoformatting.
Piotrek Koszuliński 9 éve
szülő
commit
cbd5f64b9c

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

@@ -148,7 +148,7 @@ export default class InlineAutoformatEngine {
 			}
 
 			const block = selection.focus.parent;
-			const text = getText( block ).slice( 0, selection.focus.offset + 1 );
+			const text = getText( block ).slice( 0, selection.focus.offset );
 			const ranges = testCallback( text );
 			const rangesToFormat = [];
 

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

@@ -131,5 +131,14 @@ describe( 'Autoformat', () => {
 
 			expect( getData( doc ) ).to.equal( '<paragraph>foobar*[]</paragraph>' );
 		} );
+
+		it( 'should format inside the text', () => {
+			setData( doc, '<paragraph>foo **bar*[] baz</paragraph>' );
+			doc.enqueueChanges( () => {
+				batch.insert( doc.selection.getFirstPosition(), '*' );
+			} );
+
+			expect( getData( doc ) ).to.equal( '<paragraph>foo <$text bold="true">bar</$text>[] baz</paragraph>' );
+		} );
 	} );
 } );