Fix bug where ESC was closing the Console autocompletion suggestions menu, but then also exiting edit mode. (#16500)

This commit is contained in:
CJ Cenizal 2018-02-02 16:01:40 -08:00 committed by GitHub
parent 090866c514
commit e5a10edb38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 53 deletions

View file

@ -37,8 +37,8 @@ uiModules.get('kibana')
<p class="kuiText kuiVerticalRhythmSmall">
When you&rsquo;re done, press Escape to stop editing.
</p>
</div>
`);
</div>`
);
const uiAceTextbox = element.find('textarea');
@ -63,13 +63,33 @@ uiModules.get('kibana')
enableOverlay();
});
let isAutoCompleterOpen;
// We have to capture this event on the 'capture' phase, otherewise Ace will have already
// dismissed the autocompleter when the user hits ESC.
document.addEventListener('keydown', () => {
const autoCompleter = document.querySelector('.ace_autocomplete');
if (!autoCompleter) {
isAutoCompleterOpen = false;
return;
}
// The autoComplete is just hidden when it's closed, not removed from the DOM.
isAutoCompleterOpen = autoCompleter.style.display !== 'none';
}, { capture: true });
uiAceTextbox.keydown((ev) => {
if (ev.keyCode === keyCodes.ESCAPE) {
// If the autocompletion context menu is open then we want to let ESC close it but
// **not** exit out of editing mode.
if (!isAutoCompleterOpen) {
ev.preventDefault();
ev.stopPropagation();
enableOverlay();
hint.focus();
}
}
});
hint.click(startEditing);