From f6c5fcb747440d445726694ff8978654c9cbbab5 Mon Sep 17 00:00:00 2001 From: Voiture Date: Wed, 6 Nov 2024 04:00:53 -0500 Subject: [PATCH 1/9] ESC key will scroll chat to bottom, if chat is not already pinned. --- assets/chat/js/chat.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index c0f2e020..16caa65b 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -415,7 +415,12 @@ class Chat { // ESC document.addEventListener('keydown', (e) => { - if (isKeyCode(e, KEYCODES.ESC)) ChatMenu.closeMenus(this); // ESC key + if (isKeyCode(e, KEYCODES.ESC)) { + // If any menus are open, close them first + if ([...this.menus].some(([, menu]) => menu.visible)) ChatMenu.closeMenus(this); + // If chat is not pinned, scroll to bottom + else if (!this.mainwindow.scrollplugin.pinned) this.mainwindow.scrollplugin.scrollBottom(); + } }); // Visibility From 44355fc08f54ade32a9fb491c170e2f2a2c056bd Mon Sep 17 00:00:00 2001 From: Voiture Date: Thu, 7 Nov 2024 12:37:11 -0500 Subject: [PATCH 2/9] Used getActiveWindow to work with other windows like whispers --- assets/chat/js/chat.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index 16caa65b..895b5602 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -417,9 +417,11 @@ class Chat { document.addEventListener('keydown', (e) => { if (isKeyCode(e, KEYCODES.ESC)) { // If any menus are open, close them first - if ([...this.menus].some(([, menu]) => menu.visible)) ChatMenu.closeMenus(this); + if ([...this.menus].some(([, menu]) => menu.visible)) + ChatMenu.closeMenus(this); // If chat is not pinned, scroll to bottom - else if (!this.mainwindow.scrollplugin.pinned) this.mainwindow.scrollplugin.scrollBottom(); + else if (!this.getActiveWindow().scrollplugin.pinned) + this.getActiveWindow().scrollplugin.scrollBottom(); } }); From 2617dd7b70aff302f751ae53005956910d9f54e2 Mon Sep 17 00:00:00 2001 From: Voiture Date: Thu, 7 Nov 2024 12:48:01 -0500 Subject: [PATCH 3/9] tidying --- assets/chat/js/chat.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index 895b5602..2e6044cb 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -417,11 +417,9 @@ class Chat { document.addEventListener('keydown', (e) => { if (isKeyCode(e, KEYCODES.ESC)) { // If any menus are open, close them first - if ([...this.menus].some(([, menu]) => menu.visible)) - ChatMenu.closeMenus(this); - // If chat is not pinned, scroll to bottom - else if (!this.getActiveWindow().scrollplugin.pinned) - this.getActiveWindow().scrollplugin.scrollBottom(); + if ([...this.menus].some(([, menu]) => menu.visible)) ChatMenu.closeMenus(this); + // If the active window is scrolled up (not pinned), scroll to bottom + else if (!this.getActiveWindow().scrollplugin.pinned) this.getActiveWindow().scrollplugin.scrollBottom(); } }); From 3cae812ee79f47a4d4bf32fe52a141a2af3ef020 Mon Sep 17 00:00:00 2001 From: Voiture Date: Thu, 7 Nov 2024 17:34:12 -0500 Subject: [PATCH 4/9] added getActiveMenu function --- assets/chat/js/chat.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index 2e6044cb..c89dcc85 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -417,9 +417,10 @@ class Chat { document.addEventListener('keydown', (e) => { if (isKeyCode(e, KEYCODES.ESC)) { // If any menus are open, close them first - if ([...this.menus].some(([, menu]) => menu.visible)) ChatMenu.closeMenus(this); + if (this.getActiveMenu() !== undefined) ChatMenu.closeMenus(this); // If the active window is scrolled up (not pinned), scroll to bottom - else if (!this.getActiveWindow().scrollplugin.pinned) this.getActiveWindow().scrollplugin.scrollBottom(); + else if (!this.getActiveWindow().scrollplugin.pinned) + this.getActiveWindow().scrollplugin.scrollBottom(); } }); @@ -927,6 +928,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()) { From cad88899c63ae46a087edba2e21de79759f72f7e Mon Sep 17 00:00:00 2001 From: Voiture Date: Thu, 7 Nov 2024 17:34:12 -0500 Subject: [PATCH 5/9] added getActiveMenu function --- assets/chat/js/chat.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index 2e6044cb..201ce3be 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -416,10 +416,11 @@ class Chat { // ESC document.addEventListener('keydown', (e) => { if (isKeyCode(e, KEYCODES.ESC)) { + const activeView = this.getActiveWindow().scrollplugin; // If any menus are open, close them first - if ([...this.menus].some(([, menu]) => menu.visible)) ChatMenu.closeMenus(this); + if (this.getActiveMenu() !== undefined) ChatMenu.closeMenus(this); // If the active window is scrolled up (not pinned), scroll to bottom - else if (!this.getActiveWindow().scrollplugin.pinned) this.getActiveWindow().scrollplugin.scrollBottom(); + else if (!activeView.pinned) activeView.scrollBottom(); } }); @@ -927,6 +928,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()) { From 622fbd832015dd9a18af17d9df16060261fea3c4 Mon Sep 17 00:00:00 2001 From: Voiture <48459786+Voiture-0@users.noreply.github.com> Date: Sat, 9 Nov 2024 17:06:33 -0500 Subject: [PATCH 6/9] Update chat.js --- assets/chat/js/chat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index 201ce3be..46275847 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -418,7 +418,7 @@ class Chat { if (isKeyCode(e, KEYCODES.ESC)) { const activeView = this.getActiveWindow().scrollplugin; // If any menus are open, close them first - if (this.getActiveMenu() !== undefined) ChatMenu.closeMenus(this); + if (this.getActiveMenu()) ChatMenu.closeMenus(this); // If the active window is scrolled up (not pinned), scroll to bottom else if (!activeView.pinned) activeView.scrollBottom(); } From 7a843f47f6d0cc8472c7e6df6790bdf1d6565b01 Mon Sep 17 00:00:00 2001 From: Voiture Date: Fri, 15 Nov 2024 10:18:38 -0500 Subject: [PATCH 7/9] Added methods on ChatWindow to interface with scroll plugin --- assets/chat/js/chat.js | 4 ++-- assets/chat/js/window.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index 40eb855a..fd1408ff 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -437,11 +437,11 @@ class Chat { // ESC document.addEventListener('keydown', (e) => { if (isKeyCode(e, KEYCODES.ESC)) { - const activeView = this.getActiveWindow().scrollplugin; + const activeWindow = this.getActiveWindow(); // If any menus are open, close them first if (this.getActiveMenu()) ChatMenu.closeMenus(this); // If the active window is scrolled up (not pinned), scroll to bottom - else if (!activeView.pinned) activeView.scrollBottom(); + else if (!activeWindow.isScrollPinned()) activeWindow.scrollBottom(); } }); 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. From a7f68f0b11fe3cc244667833ba416247a64a2b36 Mon Sep 17 00:00:00 2001 From: Voiture Date: Fri, 15 Nov 2024 17:35:33 -0500 Subject: [PATCH 8/9] Added hiding selected event in eventbar with ESC key --- assets/chat/js/chat.js | 11 +++++++---- assets/chat/js/event-bar/EventBar.js | 9 ++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index fd1408ff..47079651 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -438,10 +438,13 @@ class Chat { document.addEventListener('keydown', (e) => { if (isKeyCode(e, KEYCODES.ESC)) { const activeWindow = this.getActiveWindow(); - // If any menus are open, close them first - if (this.getActiveMenu()) ChatMenu.closeMenus(this); - // If the active window is scrolled up (not pinned), scroll to bottom - else if (!activeWindow.isScrollPinned()) activeWindow.scrollBottom(); + if (this.getActiveMenu()) { + ChatMenu.closeMenus(this); + } else if (this.eventBar.isEventSelected()) { + this.eventBar.unselect(); + } else if (!activeWindow.isScrollPinned()) { + activeWindow.scrollBottom(); + } } }); 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 From 5191c43994e687932e6bfa7b2ef0dd265785218d Mon Sep 17 00:00:00 2001 From: Voiture Date: Fri, 15 Nov 2024 17:41:47 -0500 Subject: [PATCH 9/9] Added ESC hotkey for clearing userfocus --- assets/chat/js/chat.js | 2 ++ assets/chat/js/focus.js | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index 47079651..05293cc1 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -444,6 +444,8 @@ class Chat { this.eventBar.unselect(); } else if (!activeWindow.isScrollPinned()) { activeWindow.scrollBottom(); + } else if (this.userfocus.isFocused()) { + this.userfocus.clearFocus(); } } }); 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()); } }