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
17 changes: 16 additions & 1 deletion assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down
9 changes: 8 additions & 1 deletion assets/chat/js/event-bar/EventBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions assets/chat/js/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -43,6 +43,10 @@ class ChatUserFocus {
return this;
}

isFocused() {
return this.focused.length > 0;
}

addCssRule(value, isFlair) {
let rule;
if (isFlair) {
Expand Down Expand Up @@ -92,7 +96,7 @@ class ChatUserFocus {
}

redraw() {
this.chat.ui.toggleClass('focus', this.focused.length > 0);
this.chat.ui.toggleClass('focus', this.isFocused());
}
}

Expand Down
8 changes: 8 additions & 0 deletions assets/chat/js/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down