close showHelp() if input element has can-close-on-esc class

This commit is contained in:
tophf 2017-12-03 00:22:03 +03:00
parent a5f31162f6
commit 904e6017f2

View File

@ -564,11 +564,23 @@ function showHelp(title = '', body) {
div.style = 'display: block'; div.style = 'display: block';
return div; return div;
function closeHelp(e) { function closeHelp(event) {
if (!e || e.type === 'click' || const canClose =
(e.which === 27 && !e.altKey && !e.ctrlKey && !e.shiftKey && !e.metaKey && !event ||
!$('.CodeMirror-hints, #message-box') && !(document.activeElement instanceof HTMLInputElement))) { event.type === 'click' ||
if (e && div.codebox && !div.codebox.options.readOnly && !div.codebox.isClean()) { (
event.which === 27 &&
!event.altKey && !event.ctrlKey && !event.shiftKey && !event.metaKey &&
!$('.CodeMirror-hints, #message-box') &&
(
!document.activeElement ||
document.activeElement.matches(':not(input), .can-close-on-esc')
)
);
if (!canClose) {
return;
}
if (event && div.codebox && !div.codebox.options.readOnly && !div.codebox.isClean()) {
messageBox.confirm(t('confirmDiscardChanges')).then(ok => ok && closeHelp()); messageBox.confirm(t('confirmDiscardChanges')).then(ok => ok && closeHelp());
return; return;
} }
@ -580,7 +592,6 @@ function showHelp(title = '', body) {
(editors.lastActive || editors[0]).focus(); (editors.lastActive || editors[0]).focus();
} }
} }
}
function showCodeMirrorPopup(title, html, options) { function showCodeMirrorPopup(title, html, options) {
const popup = showHelp(title, html); const popup = showHelp(title, html);