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

Commit

Permalink
Koenig - Improved closing of (+) menu when cursor moves
Browse files Browse the repository at this point in the history
refs TryGhost/Ghost#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 <kbd>Up</kbd> is pressed and the title is selected rather than the cursor being moved within the document
  • Loading branch information
kevinansfield committed Jun 20, 2018
1 parent 52f947d commit 2427a30
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/koenig-editor/addon/components/koenig-plus-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down Expand Up @@ -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);
},
Expand Down Expand Up @@ -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();
}
},

Expand Down

0 comments on commit 2427a30

Please sign in to comment.