From 13c402cfe81f65da24cd2d0c7719be03c7e1eaa5 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 25 Apr 2018 15:19:09 +0100 Subject: [PATCH] Koenig - Fixed error when clicking on card with /-menu open refs https://github.com/TryGhost/Ghost/issues/9505 - logic assumed that the selected section had a text property (cards do not) --- .../addon/components/koenig-slash-menu.js | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 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 aa6c519de7..c41d1f2655 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 @@ -111,19 +111,23 @@ export default Component.extend({ // update menu position to match cursor position this._positionMenu(editorRange); - // close the menu if we're on a non-slash section (eg, when / is deleted) - if (this.get('showMenu') && editorRange.head.section && editorRange.head.section.text.indexOf('/') !== 0) { - this._hideMenu(); - return; - } + if (this.get('showMenu') && editorRange) { + let {head: {section}} = editorRange; - // update the query when the menu is open and cursor is in our open range - if (this.get('showMenu') && editorRange.head.section === this._openRange.head.section) { - let query = editorRange.head.section.text.substring( - this._openRange.head.offset, - editorRange.head.offset - ); - this._updateQuery(query); + // close the menu if we're on a non-slash section (eg, when / is deleted) + if (section && section.text && section.text.indexOf('/') !== 0) { + this._hideMenu(); + return; + } + + // update the query when the menu is open and cursor is in our open range + if (section === this._openRange.head.section) { + let query = section.text.substring( + this._openRange.head.offset, + editorRange.head.offset + ); + this._updateQuery(query); + } } },