Fix closing popup sometimes being stuck via Escape
This commit is contained in:
parent
f092269c01
commit
a5baa3605f
|
@ -39,6 +39,7 @@ import { textgen_types, textgenerationwebui_settings as textgen_settings, getTex
|
||||||
import { debounce_timeout } from './constants.js';
|
import { debounce_timeout } from './constants.js';
|
||||||
|
|
||||||
import Bowser from '../lib/bowser.min.js';
|
import Bowser from '../lib/bowser.min.js';
|
||||||
|
import { Popup } from './popup.js';
|
||||||
|
|
||||||
var RPanelPin = document.getElementById('rm_button_panel_pin');
|
var RPanelPin = document.getElementById('rm_button_panel_pin');
|
||||||
var LPanelPin = document.getElementById('lm_button_panel_pin');
|
var LPanelPin = document.getElementById('lm_button_panel_pin');
|
||||||
|
@ -1096,6 +1097,9 @@ export function initRossMods() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key == 'Escape') { //closes various panels
|
if (event.key == 'Escape') { //closes various panels
|
||||||
|
// Do not close panels if we are currently inside a popup
|
||||||
|
if (Popup.util.isPopupOpen())
|
||||||
|
return;
|
||||||
|
|
||||||
//dont override Escape hotkey functions from script.js
|
//dont override Escape hotkey functions from script.js
|
||||||
//"close edit box" and "cancel stream generation".
|
//"close edit box" and "cancel stream generation".
|
||||||
|
|
|
@ -195,19 +195,19 @@ export class Popup {
|
||||||
|
|
||||||
this.ok.addEventListener('click', () => this.complete(POPUP_RESULT.AFFIRMATIVE));
|
this.ok.addEventListener('click', () => this.complete(POPUP_RESULT.AFFIRMATIVE));
|
||||||
this.cancel.addEventListener('click', () => this.complete(POPUP_RESULT.NEGATIVE));
|
this.cancel.addEventListener('click', () => this.complete(POPUP_RESULT.NEGATIVE));
|
||||||
const keyListener = (evt) => {
|
|
||||||
switch (evt.key) {
|
|
||||||
case 'Escape': {
|
|
||||||
// Check if we are the currently active popup
|
|
||||||
if (this.dlg != document.activeElement?.closest('.popup'))
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
// Bind dialog listeners manually, so we can be sure context is preserved
|
||||||
|
const cancelListener = (evt) => {
|
||||||
this.complete(POPUP_RESULT.CANCELLED);
|
this.complete(POPUP_RESULT.CANCELLED);
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
window.removeEventListener('keydown', keyListenerBound);
|
window.removeEventListener('cancel', cancelListenerBound);
|
||||||
break;
|
};
|
||||||
}
|
const cancelListenerBound = cancelListener.bind(this);
|
||||||
|
this.dlg.addEventListener('cancel', cancelListenerBound);
|
||||||
|
|
||||||
|
const keyListener = (evt) => {
|
||||||
|
switch (evt.key) {
|
||||||
case 'Enter': {
|
case 'Enter': {
|
||||||
// CTRL+Enter counts as a closing action, but all other modifiers (ALT, SHIFT) should not trigger this
|
// CTRL+Enter counts as a closing action, but all other modifiers (ALT, SHIFT) should not trigger this
|
||||||
if (evt.altKey || evt.shiftKey)
|
if (evt.altKey || evt.shiftKey)
|
||||||
|
|
Loading…
Reference in New Issue