From 7ee4b1aa9e4a7a3a4d78708647de4db1f632481c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Tue, 26 Jun 2018 09:51:16 +0200 Subject: [PATCH 1/3] Used EditorUI as an InlineEditorUI parent class. --- src/inlineeditorui.js | 39 +++++---------------------------------- tests/inlineeditorui.js | 24 +++++------------------- 2 files changed, 10 insertions(+), 53 deletions(-) diff --git a/src/inlineeditorui.js b/src/inlineeditorui.js index 4bc334c..262abe4 100644 --- a/src/inlineeditorui.js +++ b/src/inlineeditorui.js @@ -7,43 +7,21 @@ * @module editor-inline/inlineeditorui */ -import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory'; -import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker'; +import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui'; import enableToolbarKeyboardFocus from '@ckeditor/ckeditor5-ui/src/toolbar/enabletoolbarkeyboardfocus'; import normalizeToolbarConfig from '@ckeditor/ckeditor5-ui/src/toolbar/normalizetoolbarconfig'; /** * The inline editor UI class. * - * @implements module:core/editor/editorui~EditorUI + * @extends module:core/editor/editorui~EditorUI */ -export default class InlineEditorUI { +export default class InlineEditorUI extends EditorUI { /** - * Creates an instance of the editor UI class. - * - * @param {module:core/editor/editor~Editor} editor The editor instance. - * @param {module:ui/editorui/editoruiview~EditorUIView} view The view of the UI. + * @inheritDoc */ constructor( editor, view ) { - /** - * @inheritDoc - */ - this.editor = editor; - - /** - * @inheritDoc - */ - this.view = view; - - /** - * @inheritDoc - */ - this.componentFactory = new ComponentFactory( editor ); - - /** - * @inheritDoc - */ - this.focusTracker = new FocusTracker(); + super( editor, view ); /** * A normalized `config.toolbar` object. @@ -103,11 +81,4 @@ export default class InlineEditorUI { toolbar: view.toolbar } ); } - - /** - * Destroys the UI. - */ - destroy() { - this.view.destroy(); - } } diff --git a/tests/inlineeditorui.js b/tests/inlineeditorui.js index 82d90d4..99375d5 100644 --- a/tests/inlineeditorui.js +++ b/tests/inlineeditorui.js @@ -5,15 +5,13 @@ /* globals document, Event */ -import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory'; import View from '@ckeditor/ckeditor5-ui/src/view'; import InlineEditorUI from '../src/inlineeditorui'; +import EditorUI from '@ckeditor/ckeditor5-core/src/editor/editorui'; import InlineEditorUIView from '../src/inlineeditoruiview'; import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor'; -import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker'; - import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard'; import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; import utils from '@ckeditor/ckeditor5-utils/tests/_utils/utils'; @@ -41,20 +39,8 @@ describe( 'InlineEditorUI', () => { } ); describe( 'constructor()', () => { - it( 'sets #editor', () => { - expect( ui.editor ).to.equal( editor ); - } ); - - it( 'sets #view', () => { - expect( ui.view ).to.equal( view ); - } ); - - it( 'creates #componentFactory factory', () => { - expect( ui.componentFactory ).to.be.instanceOf( ComponentFactory ); - } ); - - it( 'creates #focusTracker', () => { - expect( ui.focusTracker ).to.be.instanceOf( FocusTracker ); + it( 'extends EditorUI', () => { + expect( ui ).to.instanceof( EditorUI ); } ); } ); @@ -214,8 +200,8 @@ describe( 'InlineEditorUI', () => { } ); describe( 'destroy()', () => { - it( 'destroys the #view', () => { - const spy = sinon.spy( view, 'destroy' ); + it( 'calls EditorUI#destroy', () => { + const spy = testUtils.sinon.spy( EditorUI.prototype, 'destroy' ); return editor.destroy() .then( () => { From 73e6666d592d0cd315074b51ed0366a64c33ceaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Tue, 26 Jun 2018 10:16:33 +0200 Subject: [PATCH 2/3] Used EditorUI#update instead of ViewDocument#render to pin panel. --- src/inlineeditorui.js | 2 +- tests/inlineeditorui.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/inlineeditorui.js b/src/inlineeditorui.js index 262abe4..88e6137 100644 --- a/src/inlineeditorui.js +++ b/src/inlineeditorui.js @@ -49,7 +49,7 @@ export default class InlineEditorUI extends EditorUI { } // https://github.com/ckeditor/ckeditor5-editor-inline/issues/4 - view.listenTo( editor.editing.view, 'render', () => { + view.listenTo( editor.ui, 'update', () => { // Don't pin if the panel is not already visible. It prevents the panel // showing up when there's no focus in the UI. if ( view.panel.isVisible ) { diff --git a/tests/inlineeditorui.js b/tests/inlineeditorui.js index 99375d5..f7927c3 100644 --- a/tests/inlineeditorui.js +++ b/tests/inlineeditorui.js @@ -80,17 +80,17 @@ describe( 'InlineEditorUI', () => { } ); // https://github.com/ckeditor/ckeditor5-editor-inline/issues/4 - it( 'pin() is called on editor.editable.view#render', () => { + it( 'pin() is called on editor.ui#update', () => { const spy = sinon.stub( view.panel, 'pin' ); view.panel.hide(); - editor.editing.view.render(); + editor.ui.fire( 'update' ); sinon.assert.notCalled( spy ); view.panel.show(); - editor.editing.view.render(); + editor.ui.fire( 'update' ); sinon.assert.calledOnce( spy ); sinon.assert.calledWithExactly( spy, { target: view.editableElement, From a549473b1d37d437b28e4cb39677ae44991f3523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Wed, 27 Jun 2018 16:28:06 +0200 Subject: [PATCH 3/3] Removed unnecessary test case. --- tests/inlineeditorui.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/inlineeditorui.js b/tests/inlineeditorui.js index f7927c3..0d25919 100644 --- a/tests/inlineeditorui.js +++ b/tests/inlineeditorui.js @@ -198,17 +198,6 @@ describe( 'InlineEditorUI', () => { } ); } ); } ); - - describe( 'destroy()', () => { - it( 'calls EditorUI#destroy', () => { - const spy = testUtils.sinon.spy( EditorUI.prototype, 'destroy' ); - - return editor.destroy() - .then( () => { - sinon.assert.calledOnce( spy ); - } ); - } ); - } ); } ); function viewCreator( name ) {