Skip to content

Commit

Permalink
Merge pull request #547 from Voiture-0/feature/escape-pins-chat
Browse files Browse the repository at this point in the history
Added hotkey for ESC key to scroll chat to bottom
  • Loading branch information
11k authored Nov 15, 2024
2 parents f9ee2fe + 5191c43 commit c86d965
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
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

0 comments on commit c86d965

Please sign in to comment.