浏览代码

Merge branch t/ckeditor5-engine/858

Internal: Update API usage after merge t/858 on engine.
Piotr Jasiun 8 年之前
父节点
当前提交
c620f9136f

+ 1 - 2
packages/ckeditor5-typing/src/deletecommand.js

@@ -10,7 +10,6 @@
 import Command from '@ckeditor/ckeditor5-core/src/command';
 import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
 import Element from '@ckeditor/ckeditor5-engine/src/model/element';
-import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import ChangeBuffer from './changebuffer';
 import count from '@ckeditor/ckeditor5-utils/src/count';
@@ -175,7 +174,7 @@ export default class DeleteCommand extends Command {
 		const paragraph = new Element( 'paragraph' );
 
 		this._buffer.batch.remove( Range.createIn( limitElement ) );
-		this._buffer.batch.insert( Position.createAt( limitElement ), paragraph );
+		this._buffer.batch.insert( paragraph, limitElement );
 
 		selection.setCollapsedAt( paragraph );
 	}

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

@@ -193,7 +193,10 @@ class MutationHandler {
 		// Create fresh DomConverter so it will not use existing mapping and convert current DOM to model.
 		// This wouldn't be needed if DomConverter would allow to create fresh view without checking any mappings.
 		const freshDomConverter = new DomConverter();
-		const modelFromCurrentDom = this.editor.data.toModel( freshDomConverter.domToView( domMutationCommonAncestor ) ).getChild( 0 );
+		const modelFromCurrentDom = this.editor.data.toModel(
+			freshDomConverter.domToView( domMutationCommonAncestor ),
+			this.editor.commands.get( 'input' ).buffer.batch
+		).getChild( 0 );
 
 		// Current model.
 		const currentModel = this.editor.editing.mapper.toModelElement( mutationsCommonAncestor );

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

@@ -85,7 +85,7 @@ export default class InputCommand extends Command {
 			}
 
 			if ( text ) {
-				this._buffer.batch.weakInsert( range.start, text );
+				this._buffer.batch.insertText( text, doc.selection.getAttributes(), range.start );
 			}
 
 			if ( resultRange ) {

+ 9 - 10
packages/ckeditor5-typing/tests/changebuffer.js

@@ -6,7 +6,6 @@
 import ChangeBuffer from '../src/changebuffer';
 import Document from '@ckeditor/ckeditor5-engine/src/model/document';
 import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
-import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 
 describe( 'ChangeBuffer', () => {
 	const CHANGE_LIMIT = 3;
@@ -91,7 +90,7 @@ describe( 'ChangeBuffer', () => {
 			// Ensure that size is reset too.
 			buffer.input( 1 );
 
-			doc.batch().insert( Position.createAt( root, 0 ), 'a' );
+			doc.batch().insertText( 'a', root );
 
 			expect( buffer.batch ).to.not.equal( batch1 );
 			expect( buffer.size ).to.equal( 0 );
@@ -100,31 +99,31 @@ describe( 'ChangeBuffer', () => {
 		it( 'is not reset when changes are added to the buffer\'s batch', () => {
 			const batch1 = buffer.batch;
 
-			buffer.batch.insert( Position.createAt( root, 0 ), 'a' );
+			buffer.batch.insert( 'a', root );
 			expect( buffer.batch ).to.equal( batch1 );
 
-			buffer.batch.insert( Position.createAt( root, 0 ), 'b' );
+			buffer.batch.insert( 'b', root );
 			expect( buffer.batch ).to.equal( batch1 );
 		} );
 
 		it( 'is not reset when changes are added to batch which existed previously', () => {
 			const externalBatch = doc.batch();
 
-			externalBatch.insert( Position.createAt( root, 0 ), 'a' );
+			externalBatch.insertText( 'a', root );
 
 			const bufferBatch = buffer.batch;
 
-			buffer.batch.insert( Position.createAt( root, 0 ), 'b' );
+			bufferBatch.insertText( 'b', root );
 			expect( buffer.batch ).to.equal( bufferBatch );
 
-			doc.batch().insert( Position.createAt( root, 0 ), 'c' );
+			doc.batch().insertText( 'c', root );
 			expect( buffer.batch ).to.not.equal( bufferBatch );
 		} );
 
 		it( 'is not reset when changes are applied in transparent batch', () => {
 			const bufferBatch = buffer.batch;
 
-			doc.batch( 'transparent' ).insert( Position.createAt( root, 0 ), 'a' );
+			doc.batch( 'transparent' ).insert( 'a', root );
 
 			expect( buffer.batch ).to.equal( bufferBatch );
 		} );
@@ -175,7 +174,7 @@ describe( 'ChangeBuffer', () => {
 
 			buffer.lock();
 
-			doc.batch().insert( Position.createAt( root, 0 ), 'a' );
+			doc.batch().insertText( 'a', root );
 
 			buffer.unlock();
 
@@ -236,7 +235,7 @@ describe( 'ChangeBuffer', () => {
 
 			buffer.destroy();
 
-			doc.batch().insert( Position.createAt( root, 0 ), 'a' );
+			doc.batch().insertText( 'a', root );
 
 			expect( buffer.batch ).to.equal( batch1 );
 		} );

+ 24 - 2
packages/ckeditor5-typing/tests/input.js

@@ -126,6 +126,28 @@ describe( 'Input feature', () => {
 			expect( getViewData( view ) ).to.equal( '<p>x{}</p>' );
 		} );
 
+		it( 'should apply selection attributes to the inserted text', () => {
+			setModelData( model, '<paragraph>[]</paragraph>', {
+				selectionAttributes: {
+					bold: true,
+					italic: true
+				}
+			} );
+
+			view.fire( 'mutations', [
+				{
+					type: 'children',
+					oldChildren: [],
+					newChildren: [ new ViewText( 'x' ) ],
+					node: viewRoot.getChild( 0 )
+				}
+			] );
+
+			expect( getModelData( model ) ).to.equal(
+				'<paragraph><$text bold="true" italic="true">x</$text><$text bold="true" italic="true">[]</$text></paragraph>'
+			);
+		} );
+
 		it( 'should handle multiple text mutations', () => {
 			editor.setData( '<p>foo<strong>bar</strong></p>' );
 
@@ -272,7 +294,7 @@ describe( 'Input feature', () => {
 			const viewSelection = new ViewSelection();
 			viewSelection.setCollapsedAt( viewRoot.getChild( 0 ).getChild( 0 ), 6 );
 
-			testUtils.sinon.spy( Batch.prototype, 'weakInsert' );
+			testUtils.sinon.spy( Batch.prototype, 'insert' );
 			testUtils.sinon.spy( Batch.prototype, 'remove' );
 
 			view.fire( 'mutations',
@@ -285,7 +307,7 @@ describe( 'Input feature', () => {
 				viewSelection
 			);
 
-			expect( Batch.prototype.weakInsert.calledOnce ).to.be.true;
+			expect( Batch.prototype.insert.calledOnce ).to.be.true;
 			expect( Batch.prototype.remove.calledOnce ).to.be.true;
 		} );
 

+ 1 - 1
packages/ckeditor5-typing/tests/manual/nbsp.js

@@ -27,7 +27,7 @@ ClassicEditor
 		document.querySelector( '#nbsp' ).addEventListener( 'click', () => {
 			editor.document.enqueueChanges( () => {
 				editor.document.selection.collapseToStart();
-				editor.document.batch().weakInsert( editor.document.selection.getFirstPosition(), '\u00A0' );
+				editor.document.batch().insertText( '\u00A0', editor.document.selection.getFirstPosition() );
 			} );
 		} );