mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
only close last popup with escape
This commit is contained in:
@@ -22,6 +22,10 @@ export const POPUP_RESULT = {
|
|||||||
|
|
||||||
|
|
||||||
export class Popup {
|
export class Popup {
|
||||||
|
/**@type {Popup[]}*/
|
||||||
|
static stack = [];
|
||||||
|
|
||||||
|
|
||||||
/**@type {POPUP_TYPE}*/ type;
|
/**@type {POPUP_TYPE}*/ type;
|
||||||
|
|
||||||
/**@type {HTMLElement}*/ dom;
|
/**@type {HTMLElement}*/ dom;
|
||||||
@@ -119,6 +123,7 @@ export class Popup {
|
|||||||
const keyListener = (evt) => {
|
const keyListener = (evt) => {
|
||||||
switch (evt.key) {
|
switch (evt.key) {
|
||||||
case 'Escape': {
|
case 'Escape': {
|
||||||
|
if (Popup.stack.slice(-1)[0] == this) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
this.completeCancelled();
|
this.completeCancelled();
|
||||||
@@ -126,12 +131,14 @@ export class Popup {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const keyListenerBound = keyListener.bind(this);
|
const keyListenerBound = keyListener.bind(this);
|
||||||
window.addEventListener('keydown', keyListenerBound);
|
window.addEventListener('keydown', keyListenerBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
async show() {
|
async show() {
|
||||||
|
Popup.stack.push(this);
|
||||||
document.body.append(this.dom);
|
document.body.append(this.dom);
|
||||||
this.dom.style.display = 'block';
|
this.dom.style.display = 'block';
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
@@ -198,6 +205,7 @@ export class Popup {
|
|||||||
|
|
||||||
|
|
||||||
hide() {
|
hide() {
|
||||||
|
Popup.stack.splice(Popup.stack.indexOf(this), 1);
|
||||||
$(this.dom).transition({
|
$(this.dom).transition({
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
duration: animation_duration,
|
duration: animation_duration,
|
||||||
|
Reference in New Issue
Block a user