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

Replace ' ' with spaces in inserted text.

Krzysztof Krztoń 9 лет назад
Родитель
Сommit
f1b78a5159
2 измененных файлов с 56 добавлено и 1 удалено
  1. 1 1
      packages/ckeditor5-typing/src/input.js
  2. 55 0
      packages/ckeditor5-typing/tests/input.js

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

@@ -218,7 +218,7 @@ class MutationHandler {
 		}
 		}
 
 
 		// Insert appropriate characters basing on `mutation.text`.
 		// Insert appropriate characters basing on `mutation.text`.
-		const insertedText = mutation.newText.substr( firstChangeAt, insertions );
+		const insertedText = newText.substr( firstChangeAt, insertions );
 		this._insert( modelPos, insertedText );
 		this._insert( modelPos, insertedText );
 
 
 		// If there was `viewSelection` and it got correctly mapped, collapse selection at found model position.
 		// If there was `viewSelection` and it got correctly mapped, collapse selection at found model position.

+ 55 - 0
packages/ckeditor5-typing/tests/input.js

@@ -244,6 +244,61 @@ describe( 'Input feature', () => {
 			expect( Batch.prototype.weakInsert.calledOnce ).to.be.true;
 			expect( Batch.prototype.weakInsert.calledOnce ).to.be.true;
 			expect( Batch.prototype.remove.calledOnce ).to.be.true;
 			expect( Batch.prototype.remove.calledOnce ).to.be.true;
 		} );
 		} );
+
+		it( 'should replace last   with space', () => {
+			model.enqueueChanges( () => {
+				model.selection.setRanges( [
+					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 6, modelRoot.getChild( 0 ), 6 )
+				] );
+			} );
+
+			view.fire( 'mutations', [
+				{
+					type: 'text',
+					oldText: 'foobar',
+					newText: 'foobar\u00A0',
+					node: viewRoot.getChild( 0 ).getChild( 0 )
+				}
+			] );
+
+			expect( getModelData( model ) ).to.equal( '<paragraph>foobar []</paragraph>' );
+			expect( getViewData( view ) ).to.equal( '<p>foobar {}</p>' );
+		} );
+
+		it( 'should replace first &nbsp; with space', () => {
+			model.enqueueChanges( () => {
+				model.selection.setRanges( [
+					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 6, modelRoot.getChild( 0 ), 6 )
+				] );
+			} );
+
+			view.fire( 'mutations', [
+				{
+					type: 'text',
+					oldText: 'foobar',
+					newText: '\u00A0foobar',
+					node: viewRoot.getChild( 0 ).getChild( 0 )
+				}
+			] );
+
+			expect( getModelData( model ) ).to.equal( '<paragraph> foobar[]</paragraph>' );
+			expect( getViewData( view ) ).to.equal( '<p> foobar{}</p>' );
+		} );
+
+		it( 'should replace all &nbsp; with spaces', () => {
+			view.fire( 'mutations', [
+				{
+					type: 'text',
+					oldText: 'foobar',
+					newText: 'foobar\u00A0\u00A0\u00A0baz',
+					node: viewRoot.getChild( 0 ).getChild( 0 )
+				}
+			] );
+
+			expect( getModelData( model ) ).to.equal( '<paragraph>foo[]bar   baz</paragraph>' );
+			expect( getViewData( view ) ).to.equal( '<p>foo{}bar' +
+				'   baz</p>' );
+		} );
 	} );
 	} );
 
 
 	describe( 'keystroke handling', () => {
 	describe( 'keystroke handling', () => {