Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 5def43c

Browse files
committed
🐛 Koenig - Fixed /-menu not working after the editor is reloaded
refs TryGhost/Ghost#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
1 parent 875356b commit 5def43c

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

lib/koenig-editor/addon/components/koenig-slash-menu.js

+13-14
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,27 @@ export default Component.extend({
5858
return map;
5959
}),
6060

61-
init() {
62-
this._super(...arguments);
63-
let editor = this.editor;
64-
65-
// register `/` text input for positioning & showing the menu
66-
editor.onTextInput({
67-
name: 'slash_menu',
68-
text: '/',
69-
run: run.bind(this, this._showMenu)
70-
});
71-
},
72-
7361
didReceiveAttrs() {
7462
this._super(...arguments);
75-
let editorRange = this.editorRange;
63+
64+
// re-register the / text input handler if the editor changes such as
65+
// when a "New story" is clicked from the sidebar or a different post
66+
// is loaded via search
67+
if (this.editor !== this._lastEditor) {
68+
this.editor.onTextInput({
69+
name: 'slash_menu',
70+
text: '/',
71+
run: run.bind(this, this._showMenu)
72+
});
73+
}
74+
this._lastEditor = this.editor;
7675

7776
// re-position the menu and update the query if necessary when the
7877
// cursor position changes
78+
let editorRange = this.editorRange;
7979
if (editorRange !== this._lastEditorRange) {
8080
this._handleCursorChange(editorRange);
8181
}
82-
8382
this._lastEditorRange = editorRange;
8483
},
8584

0 commit comments

Comments
 (0)