8
0
Просмотр исходного кода

Added shorthand focus() method

Paweł Smyrek 5 лет назад
Родитель
Сommit
da3be9ca18

+ 7 - 0
packages/ckeditor5-core/src/editor/editor.js

@@ -296,6 +296,13 @@ export default class Editor {
 		}
 	}
 
+	/**
+	 * Shorthand for {@link module:engine/view/view~View#focus `this.editing.view.focus()`}.
+	 */
+	focus() {
+		this.editing.view.focus();
+	}
+
 	/**
 	 * Creates and initializes a new editor instance.
 	 *

+ 11 - 0
packages/ckeditor5-core/tests/editor/editor.js

@@ -556,6 +556,17 @@ describe( 'Editor', () => {
 		} );
 	} );
 
+	describe( 'focus()', () => {
+		it( 'should call view\'s focus() method', () => {
+			const editor = new TestEditor();
+			const focusSpy = sinon.spy( editor.editing.view, 'focus' );
+
+			editor.focus();
+
+			expect( focusSpy.calledOnce ).to.be.true;
+		} );
+	} );
+
 	describe( 'create()', () => {
 		it( 'should return a promise that resolves properly', () => {
 			const promise = TestEditor.create();