瀏覽代碼

Changes in Position, AttributeDelta, AttributeOperation connected with TextNode -> CharacterProxy, PositionIterator -> TreeWalker.

Szymon Cofalik 10 年之前
父節點
當前提交
90817dc54d

+ 3 - 3
packages/ckeditor5-engine/src/treemodel/delta/attributedelta.js

@@ -10,7 +10,7 @@ import register from './register.js';
 import AttributeOperation from '../operation/attributeoperation.js';
 import Position from '../position.js';
 import Range from '../range.js';
-import PositionIterator from '../positioniterator.js';
+import TreeWalker from '../treewalker.js';
 import Attribute from '../attribute.js';
 import Element from '../element.js';
 
@@ -115,8 +115,8 @@ function changeRange( doc, delta, key, value, range ) {
 	while ( !next.done ) {
 		// We check values only when the range contains given element, that is when the iterator "enters" the element.
 		// To prevent double-checking or not needed checking, we filter-out iterator values for ELEMENT_LEAVE position.
-		if ( next.value.type != PositionIterator.ELEMENT_LEAVE ) {
-			valueAfter = next.value.node.attrs.getValue( key );
+		if ( next.value.type != TreeWalker.ELEMENT_LEAVE ) {
+			valueAfter = next.value.item.attrs.getValue( key );
 
 			// At the first run of the iterator the position in undefined. We also do not have a valueBefore, but
 			// because valueAfter may be null, valueBefore may be equal valueAfter ( undefined == null ).

+ 5 - 5
packages/ckeditor5-engine/src/treemodel/operation/attributeoperation.js

@@ -7,8 +7,8 @@
 
 import Operation from './operation.js';
 import Range from '../range.js';
+import TextFragment from '../textfragment.js';
 import CKEditorError from '../../ckeditorerror.js';
-import TextNode from '../textnode.js';
 
 /**
  * Operation to change nodes' attribute. Using this class you can add, remove or change value of the attribute.
@@ -99,8 +99,8 @@ export default class AttributeOperation extends Operation {
 		// Remove or change.
 		if ( oldAttr !== null ) {
 			for ( let node of this.range.getAllNodes( true ) ) {
-				if ( node instanceof TextNode ) {
-					node = node._textItem;
+				if ( node instanceof TextFragment ) {
+					node = node.first._nodeListText;
 				}
 
 				if ( !node.attrs.has( oldAttr ) ) {
@@ -126,8 +126,8 @@ export default class AttributeOperation extends Operation {
 		// Insert or change.
 		if ( newAttr !== null ) {
 			for ( let node of this.range.getAllNodes( true ) ) {
-				if ( node instanceof TextNode ) {
-					node = node._textItem;
+				if ( node instanceof TextFragment ) {
+					node = node.first._nodeListText;
 				}
 
 				if ( oldAttr === null && node.attrs.has( newAttr.key ) ) {

+ 1 - 3
packages/ckeditor5-engine/src/treemodel/position.js

@@ -433,9 +433,7 @@ export default class Position {
 			throw new CKEditorError( 'position-after-root: You can not make position after root.', { root: node } );
 		}
 
-		let length = node.text ? node.text.length : 1;
-
-		return this.createFromParentAndOffset( node.parent, node.getIndex() + length );
+		return this.createFromParentAndOffset( node.parent, node.getIndex() + 1 );
 	}
 
 	/**