8
0
فهرست منبع

Merge pull request #33 from ckeditor/t/31

FocusTracker integration
Aleksander Nowodzinski 9 سال پیش
والد
کامیت
5f1c85735f

+ 5 - 2
packages/ckeditor5-editor-classic/src/classiceditorui.js

@@ -76,7 +76,7 @@ export default class ClassicEditorUI extends BoxedEditorUI {
 			config: this.editor.config.get( 'toolbar' )
 		} );
 
-		model.bind( 'isActive' ).to( editor.editing.view.getRoot(), 'isFocused' );
+		model.bind( 'isActive' ).to( editor.focusTracker, 'isFocused' );
 
 		const toolbar = new StickyToolbar( model, new StickyToolbarView( editor.locale ), editor );
 		this.add( 'top', toolbar );
@@ -85,7 +85,7 @@ export default class ClassicEditorUI extends BoxedEditorUI {
 	}
 
 	/**
-	 * Creates the main editable of the editor.
+	 * Creates the main editable of the editor and registers it in {@link core.editor.Editor#focusTracker}.
 	 *
 	 * @protected
 	 * @returns {ui.editableUI.EditableUI}
@@ -98,6 +98,9 @@ export default class ClassicEditorUI extends BoxedEditorUI {
 
 		this.add( 'main', editableUI );
 
+		// @TODO: Do it automatically ckeditor5-core#23
+		editor.focusTracker.add( editableUI.view.element );
+
 		return editableUI;
 	}
 }

+ 20 - 1
packages/ckeditor5-editor-classic/tests/classiceditorui.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-/* globals document */
+/* globals document, Event */
 /* bender-tags: editor, browser-only */
 
 import ClassicEditorUI from '/ckeditor5/editor-classic/classiceditorui.js';
@@ -45,10 +45,29 @@ describe( 'ClassicEditorUI', () => {
 			expect( editorUI.toolbar.view ).to.be.instanceof( StickyToolbarView );
 		} );
 
+		it( 'binds editorUI.toolbar#model to editor.focusTracker', () => {
+			expect( editorUI.toolbar.model.isActive ).to.false;
+
+			editor.focusTracker.isFocused = true;
+
+			expect( editorUI.toolbar.model.isActive ).to.true;
+		} );
+
 		it( 'creates editable', () => {
 			expect( editorUI.editable ).to.be.instanceof( EditableUI );
 			expect( editorUI.editable.view ).to.be.instanceof( InlineEditableUIView );
 		} );
+
+		it( 'registers editable element in editor Focus Tracker', () => {
+			return editorUI.init()
+				.then( () => {
+					editor.focusTracker.isFocused = false;
+
+					editorUI.editable.view.element.dispatchEvent( new Event( 'focus' ) );
+
+					expect( editor.focusTracker.isFocused ).to.true;
+				} );
+		} );
 	} );
 
 	describe( 'editableElement', () => {