From e79120c339318ab7cdcdfc981548a83be5cf5366 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 20 Jun 2018 15:45:43 +0100 Subject: [PATCH] Koenig - Improved closing of (+) menu when cursor moves refs https://github.com/TryGhost/Ghost/issues/9623 - close menu if it's open and the cursor position changes within the document - closes when you start typing rather than hiding text behind the menu - watch for arrow keys and close the menu if pressed - closes when Up is pressed and the title is selected rather than the cursor being moved within the document --- .../addon/components/koenig-plus-menu.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-plus-menu.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-plus-menu.js index d9c084bdd5..7f3f3395ad 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-plus-menu.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-plus-menu.js @@ -65,6 +65,11 @@ export default Component.extend({ run.next(this, this._positionMenu); } + // hide the menu if the editor range has changed + if (this.showMenu && editorRange && !editorRange.isBlank && !editorRange.isEqual(this._lastEditorRange)) { + this._hideMenu(); + } + this._lastEditorRange = editorRange; }, @@ -166,7 +171,7 @@ export default Component.extend({ this._onWindowMousedownHandler = run.bind(this, this._handleWindowMousedown); window.addEventListener('mousedown', this._onWindowMousedownHandler); - // watch for keydown events so that we can close the mnu on Escape + // watch for keydown events so that we can close the menu on Escape this._onKeydownHandler = run.bind(this, this._handleKeydown); window.addEventListener('keydown', this._onKeydownHandler); }, @@ -252,6 +257,12 @@ export default Component.extend({ // reset the caret position so we have a caret after closing this._moveCaretToCachedEditorRange(); this._hideMenu(); + return; + } + + let arrowKeys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']; + if (arrowKeys.includes(event.code)) { + this._hideMenu(); } },