Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hotkey for ESC key to scroll chat to bottom #547

Merged
merged 11 commits into from
Nov 15, 2024
12 changes: 11 additions & 1 deletion assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,13 @@ class Chat {

// ESC
document.addEventListener('keydown', (e) => {
if (isKeyCode(e, KEYCODES.ESC)) ChatMenu.closeMenus(this); // ESC key
if (isKeyCode(e, KEYCODES.ESC)) {
const activeView = this.getActiveWindow().scrollplugin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can go ahead and add a method to ChatWindow that scrolls it to the bottom so you don't have to interface with its scroll plugin directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Added methods on ChatWindow to interface with its scroll plugin

// If any menus are open, close them first
if (this.getActiveMenu() !== undefined) ChatMenu.closeMenus(this);
vyneer marked this conversation as resolved.
Show resolved Hide resolved
// If the active window is scrolled up (not pinned), scroll to bottom
else if (!activeView.pinned) activeView.scrollBottom();
}
});

// Visibility
Expand Down Expand Up @@ -922,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()) {
Expand Down