瀏覽代碼

Removed DocumentSelection#clearAttributes.

Maciej Bukowski 7 年之前
父節點
當前提交
acef0131f5

+ 1 - 1
packages/ckeditor5-engine/src/controller/datacontroller.js

@@ -195,7 +195,7 @@ export default class DataController {
 			// Clearing selection is a workaround for ticket #569 (LiveRange loses position after removing data from document).
 			// After fixing it this code should be removed.
 			writer.setSelection( null );
-			writer.clearSelectionAttributes();
+			writer.removeSelectionAttribute( this.model.document.selection.getAttributeKeys() );
 
 			writer.remove( ModelRange.createIn( modelRoot ) );
 			writer.insert( this.parse( data ), modelRoot );

+ 1 - 1
packages/ckeditor5-engine/src/dev-utils/model.js

@@ -116,7 +116,7 @@ export function setData( model, data, options = {} ) {
 
 		// Clean up previous document selection.
 		writer.setSelection( null );
-		writer.clearSelectionAttributes();
+		writer.removeSelectionAttribute( model.document.selection.getAttributeKeys() );
 
 		// Update document selection if specified.
 		if ( selection ) {

+ 0 - 13
packages/ckeditor5-engine/src/model/documentselection.js

@@ -351,19 +351,6 @@ export default class DocumentSelection {
 	}
 
 	/**
-	 * Removes all attributes from the selection.
-	 *
-	 * If there were any attributes in selection, fires the {@link #event:change} event with
-	 * removed attributes' keys.
-	 *
-	 * @protected
-	 * @fires change:attribute
-	 */
-	_clearAttributes() {
-		this._selection.clearAttributes();
-	}
-
-	/**
 	 * Returns an iterable that iterates through all selection attributes stored in current selection's parent.
 	 *
 	 * @protected

+ 0 - 19
packages/ckeditor5-engine/src/model/writer.js

@@ -922,25 +922,6 @@ export default class Writer {
 		selection._removeAttribute( key );
 	}
 
-	clearSelectionAttributes() {
-		this._assertWriterUsageCorrectness();
-
-		const selection = this.model.document.selection;
-
-		// Sets selection attributes stored in current selection's parent node to given set of attributes.
-		if ( selection.isCollapsed && selection.anchor.parent.isEmpty ) {
-			const selectionParent = selection.anchor.parent;
-
-			for ( const [ oldKey ] of selection._getStoredAttributes() ) {
-				const storeKey = DocumentSelection._getStoreAttributeKey( oldKey );
-
-				this.removeAttribute( storeKey, selectionParent );
-			}
-		}
-
-		selection._clearAttributes();
-	}
-
 	/**
 	 * Throws `writer-detached-writer-tries-to-modify-model` error when the writer is used outside of the `change()` block.
 	 *

+ 1 - 1
packages/ckeditor5-engine/tests/dev-utils/model.js

@@ -336,7 +336,7 @@ describe( 'model test utils', () => {
 					writer.setSelection( root, 'end' );
 
 					// Needed due to https://github.com/ckeditor/ckeditor5-engine/issues/320.
-					writer.clearSelectionAttributes();
+					writer.removeSelectionAttribute( model.document.selection.getAttributeKeys() );
 				} );
 
 				expect( stringify( root, selection ) ).to.equal(

+ 0 - 17
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -739,23 +739,6 @@ describe( 'DocumentSelection', () => {
 			} );
 		} );
 
-		describe( 'clearAttributes()', () => {
-			it( 'should remove all stored attributes if the selection is in empty node', () => {
-				selection._setTo( [ rangeInEmptyP ] );
-				selection._setAttribute( 'foo', 'bar' );
-				selection._setAttribute( 'abc', 'xyz' );
-
-				selection._clearAttributes();
-
-				expect( selection.getAttribute( 'foo' ) ).to.be.undefined;
-				expect( selection.getAttribute( 'abc' ) ).to.be.undefined;
-
-				// TODO
-				// expect( emptyP.hasAttribute( fooStoreAttrKey ) ).to.be.false;
-				// expect( emptyP.hasAttribute( abcStoreAttrKey ) ).to.be.false;
-			} );
-		} );
-
 		describe( '_getStoredAttributes()', () => {
 			it( 'should return no values if there are no ranges in selection', () => {
 				const values = Array.from( selection._getStoredAttributes() );