From beab7a7a4f3d49173d10614d2fe132634c62e285 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 11 Jul 2018 15:08:51 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Koenig=20-=20Fixed=20/-menu=20no?= =?UTF-8?q?t=20working=20after=20the=20editor=20is=20reloaded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://github.com/TryGhost/Ghost/issues/9724 - if the editor was reloaded by changing the post model either through clicking "New story" or using the search from the editor screen the /-menu would stop working - keep track of the last seen `editor` instance inside `{{koenig-slash-menu}}` and register the `/` text input handler on the new editor instance if it changes --- .../addon/components/koenig-slash-menu.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-slash-menu.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-slash-menu.js index 51b6bc4bf6..98d3445487 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-slash-menu.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-slash-menu.js @@ -58,28 +58,27 @@ export default Component.extend({ return map; }), - init() { - this._super(...arguments); - let editor = this.editor; - - // register `/` text input for positioning & showing the menu - editor.onTextInput({ - name: 'slash_menu', - text: '/', - run: run.bind(this, this._showMenu) - }); - }, - didReceiveAttrs() { this._super(...arguments); - let editorRange = this.editorRange; + + // re-register the / text input handler if the editor changes such as + // when a "New story" is clicked from the sidebar or a different post + // is loaded via search + if (this.editor !== this._lastEditor) { + this.editor.onTextInput({ + name: 'slash_menu', + text: '/', + run: run.bind(this, this._showMenu) + }); + } + this._lastEditor = this.editor; // re-position the menu and update the query if necessary when the // cursor position changes + let editorRange = this.editorRange; if (editorRange !== this._lastEditorRange) { this._handleCursorChange(editorRange); } - this._lastEditorRange = editorRange; },