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 <kbd>Up</kbd> is pressed and the title is selected rather than the cursor being moved within the document
This commit is contained in:
Kevin Ansfield 2018-06-20 15:45:43 +01:00
parent 7ae1df7c8d
commit e79120c339

View File

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