8
0
Pārlūkot izejas kodu

Refactoring: Tried to made the logic more comprehensible.

Piotrek Koszuliński 9 gadi atpakaļ
vecāks
revīzija
878aff616a
1 mainītis faili ar 19 papildinājumiem un 8 dzēšanām
  1. 19 8
      packages/ckeditor5-engine/src/view/renderer.js

+ 19 - 8
packages/ckeditor5-engine/src/view/renderer.js

@@ -184,15 +184,16 @@ export default class Renderer {
 			this._removeInlineFiller();
 			this._removeInlineFiller();
 		}
 		}
 
 
-		if ( this._needsInlineFillerAtSelection() ) {
+		// If we've got the filler, let's try to guess its position in the view.
+		if ( this._inlineFiller ) {
+			inlineFillerPosition = this._getInlineFillerPosition();
+		}
+		// Othewise, if it's needed, set it at the selection position.
+		else if ( this._needsInlineFillerAtSelection() ) {
 			inlineFillerPosition = this.selection.getFirstPosition();
 			inlineFillerPosition = this.selection.getFirstPosition();
 
 
 			// Do not use `markToSync` so it will be added even if the parent is already added.
 			// Do not use `markToSync` so it will be added even if the parent is already added.
 			this.markedChildren.add( inlineFillerPosition.parent );
 			this.markedChildren.add( inlineFillerPosition.parent );
-		} else if ( this._inlineFiller ) {
-			if ( this.selection.getFirstPosition().parent instanceof ViewText ) {
-				inlineFillerPosition = ViewPosition.createBefore( this.selection.getFirstPosition().parent );
-			}
 		}
 		}
 
 
 		for ( let node of this.markedTexts ) {
 		for ( let node of this.markedTexts ) {
@@ -216,10 +217,10 @@ export default class Renderer {
 		this.markedAttributes.clear();
 		this.markedAttributes.clear();
 		this.markedChildren.clear();
 		this.markedChildren.clear();
 
 
-		this._storeInlineFiller( inlineFillerPosition );
+		this._setInlineFillerPosition( inlineFillerPosition );
 	}
 	}
 
 
-	_storeInlineFiller( fillerPosition ) {
+	_setInlineFillerPosition( fillerPosition ) {
 		if ( !fillerPosition ) {
 		if ( !fillerPosition ) {
 			this._inlineFiller = null;
 			this._inlineFiller = null;
 
 
@@ -229,12 +230,22 @@ export default class Renderer {
 		const domPosition = this.domConverter.viewPositionToDom( fillerPosition );
 		const domPosition = this.domConverter.viewPositionToDom( fillerPosition );
 
 
 		if ( !domPosition || !startsWithFiller( domPosition.parent ) ) {
 		if ( !domPosition || !startsWithFiller( domPosition.parent ) ) {
-			throw new CKEditorError( 'filler-cannot-find-node' );
+			throw new CKEditorError( 'view-renderer-cannot-find-filler' );
 		}
 		}
 
 
 		this._inlineFiller = domPosition.parent;
 		this._inlineFiller = domPosition.parent;
 	}
 	}
 
 
+	_getInlineFillerPosition() {
+		const firstPos = this.selection.getFirstPosition();
+
+		if ( firstPos.parent  instanceof ViewText ) {
+			return ViewPosition.createBefore( this.selection.getFirstPosition().parent );
+		} else {
+			return firstPos;
+		}
+	}
+
 	/**
 	/**
 	 * Returns `true` if the selection hasn't left the inline filler's text node.
 	 * Returns `true` if the selection hasn't left the inline filler's text node.
 	 * If it is `true` it means that the filler had been added for a reason and the selection does not
 	 * If it is `true` it means that the filler had been added for a reason and the selection does not