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

Do not run text transformations on selection change.

Maciej Gołaszewski 6 лет назад
Родитель
Сommit
f29129114c

+ 1 - 1
packages/ckeditor5-typing/src/texttransformation.js

@@ -83,7 +83,7 @@ export default class TextTransformation extends Plugin {
 
 
 			const watcher = new TextWatcher( editor.model, testCallback );
 			const watcher = new TextWatcher( editor.model, testCallback );
 
 
-			watcher.on( 'matched', ( evt, data ) => {
+			watcher.on( 'matched:data', ( evt, data ) => {
 				const selection = editor.model.document.selection;
 				const selection = editor.model.document.selection;
 				const focus = selection.focus;
 				const focus = selection.focus;
 				const textToReplaceLength = data.text.length;
 				const textToReplaceLength = data.text.length;

+ 10 - 0
packages/ckeditor5-typing/tests/texttransformation.js

@@ -41,6 +41,16 @@ describe( 'Text transformation feature', () => {
 	describe( 'transformations', () => {
 	describe( 'transformations', () => {
 		beforeEach( createEditorInstance );
 		beforeEach( createEditorInstance );
 
 
+		it( 'should not work for selection changes', () => {
+			setData( model, '<paragraph>foo bar(tm) baz[]</paragraph>' );
+
+			model.change( writer => {
+				writer.setSelection( doc.getRoot().getChild( 0 ), 11 );
+			} );
+
+			expect( getData( model, { withoutSelection: true } ) ).to.equal( '<paragraph>foo bar(tm) baz</paragraph>' );
+		} );
+
 		describe( 'symbols', () => {
 		describe( 'symbols', () => {
 			testTransformation( '(c)', '©' );
 			testTransformation( '(c)', '©' );
 			testTransformation( '(tm)', '™' );
 			testTransformation( '(tm)', '™' );