Browse Source

Move filler quirks handling from the TreeView to the filler utils.

Piotr Jasiun 9 years ago
parent
commit
142a72c779

+ 32 - 0
packages/ckeditor5-engine/src/treeview/filler.js

@@ -5,6 +5,8 @@
 
 'use strict';
 
+import { keyCodes } from '../../utils/keyboard.js';
+
 /**
  * Set of utils related to block and inline fillers handling.
  *
@@ -142,3 +144,33 @@ export function isBlockFiller( domNode, blockFiller ) {
 
 	return domNode.isEqualNode( templateBlockFiller );
 }
+
+/**
+ * Assign key observer which move cursor from the end of the inline filler to the begging of it when
+ * the left arrow is pressed, so the filler does not break navigation.
+ *
+ * @param {engine.treeView.TreeView} treeView TreeView instance we should inject quirks handling on.
+ */
+export function injectQuirksHandling( treeView ) {
+	treeView.on( 'keydown', jumpOverInlineFiller );
+}
+
+// Move cursor from the end of the inline filler to the begging of it when, so the filler does not break navigation.
+function jumpOverInlineFiller( evt, data ) {
+	if ( data.keyCode == keyCodes.arrowleft ) {
+		const domSelection = data.domTarget.ownerDocument.defaultView.getSelection();
+
+		if ( domSelection.rangeCount == 1 && domSelection.getRangeAt( 0 ).collapsed ) {
+			const domParent = domSelection.getRangeAt( 0 ).startContainer;
+			const domOffset = domSelection.getRangeAt( 0 ).startOffset;
+
+			if ( startsWithFiller( domParent ) && domOffset <= INLINE_FILLER_LENGTH ) {
+				const domRange = new Range();
+				domRange.setStart( domParent, 0 );
+				domRange.collapse( true );
+				domSelection.removeAllRanges();
+				domSelection.addRange( domRange );
+			}
+		}
+	}
+}

+ 2 - 25
packages/ckeditor5-engine/src/treeview/treeview.js

@@ -9,11 +9,10 @@ import Selection from './selection.js';
 import Renderer from './renderer.js';
 import Writer from './writer.js';
 import DomConverter from './domconverter.js';
-import { INLINE_FILLER_LENGTH, startsWithFiller } from './filler.js';
+import { injectQuirksHandling } from './filler.js';
 
 import mix from '../../utils/mix.js';
 import EmitterMixin from '../../utils/emittermixin.js';
-import { keyCodes } from '../../utils/keyboard.js';
 
 /**
  * TreeView class creates an abstract layer over the content editable area.
@@ -89,9 +88,7 @@ export default class TreeView {
 		 */
 		this._observers = new Map();
 
-		// Assign key observer which move cursor from the end of the inline filler to the begging of it when
-		// the left arrow is pressed, so the filler does not break navigation.
-		this.on( 'keydown', jumpOverInlineFiller );
+		injectQuirksHandling( this );
 	}
 
 	/**
@@ -200,26 +197,6 @@ export default class TreeView {
 
 mix( TreeView, EmitterMixin );
 
-// Move cursor from the end of the inline filler to the begging of it when, so the filler does not break navigation.
-function jumpOverInlineFiller( evt, data ) {
-	if ( data.keyCode == keyCodes.arrowleft ) {
-		const domSelection = data.domTarget.ownerDocument.defaultView.getSelection();
-
-		if ( domSelection.rangeCount == 1 && domSelection.getRangeAt( 0 ).collapsed ) {
-			const domParent = domSelection.getRangeAt( 0 ).startContainer;
-			const domOffset = domSelection.getRangeAt( 0 ).startOffset;
-
-			if ( startsWithFiller( domParent ) && domOffset <= INLINE_FILLER_LENGTH ) {
-				const domRange = new Range();
-				domRange.setStart( domParent, 0 );
-				domRange.collapse( true );
-				domSelection.removeAllRanges();
-				domSelection.addRange( domRange );
-			}
-		}
-	}
-}
-
 /**
  * Enum representing type of the change.
  *