diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index cf74b956..05293cc1 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -436,7 +436,18 @@ class Chat { // ESC document.addEventListener('keydown', (e) => { - if (isKeyCode(e, KEYCODES.ESC)) ChatMenu.closeMenus(this); // ESC key + if (isKeyCode(e, KEYCODES.ESC)) { + const activeWindow = this.getActiveWindow(); + if (this.getActiveMenu()) { + ChatMenu.closeMenus(this); + } else if (this.eventBar.isEventSelected()) { + this.eventBar.unselect(); + } else if (!activeWindow.isScrollPinned()) { + activeWindow.scrollBottom(); + } else if (this.userfocus.isFocused()) { + this.userfocus.clearFocus(); + } + } }); // Visibility @@ -943,6 +954,10 @@ class Chat { if (this.mainwindow !== null) this.mainwindow.update(); } + getActiveMenu() { + return [...this.menus.values()].find((menu) => menu.visible); + } + censor(nick) { for (const message of this.mainwindow.messages) { if (message.user?.username === nick.toLowerCase()) { diff --git a/assets/chat/js/event-bar/EventBar.js b/assets/chat/js/event-bar/EventBar.js index 3755c12a..69c5bbbc 100644 --- a/assets/chat/js/event-bar/EventBar.js +++ b/assets/chat/js/event-bar/EventBar.js @@ -69,7 +69,7 @@ export default class ChatEventBar extends EventEmitter { * Unselects the currently highlighted event. */ unselect() { - if (this.eventSelectUI.hasChildNodes()) { + if (this.isEventSelected()) { this.eventSelectUI.replaceChildren(); this.eventSelectUI.classList.add('hidden'); this.emit('eventUnselected'); @@ -91,6 +91,13 @@ export default class ChatEventBar extends EventEmitter { this.emit('eventSelected'); } + /** + * Returns true if an event is currently selected + */ + isEventSelected() { + return this.eventSelectUI.hasChildNodes(); + } + /** * Checks if the specified event is already in the event bar. * @param {string} uuid diff --git a/assets/chat/js/focus.js b/assets/chat/js/focus.js index 7ff52857..9330c16a 100644 --- a/assets/chat/js/focus.js +++ b/assets/chat/js/focus.js @@ -24,7 +24,7 @@ class ChatUserFocus { this.toggleFocus(t.text()); } else if (t.hasClass('flair')) { this.toggleFocus(t.data('flair'), true); - } else if (this.focused.length > 0) { + } else if (this.isFocused()) { this.clearFocus(); } } @@ -43,6 +43,10 @@ class ChatUserFocus { return this; } + isFocused() { + return this.focused.length > 0; + } + addCssRule(value, isFlair) { let rule; if (isFlair) { @@ -92,7 +96,7 @@ class ChatUserFocus { } redraw() { - this.chat.ui.toggleClass('focus', this.focused.length > 0); + this.chat.ui.toggleClass('focus', this.isFocused()); } } diff --git a/assets/chat/js/window.js b/assets/chat/js/window.js index 9c57a436..30703321 100644 --- a/assets/chat/js/window.js +++ b/assets/chat/js/window.js @@ -117,6 +117,14 @@ class ChatWindow extends EventEmitter { } } + isScrollPinned() { + return this.scrollplugin.pinned; + } + + scrollBottom() { + this.scrollplugin.scrollBottom(); + } + /** * Use chat state (settings and authentication data) to update the messages in * this window.