mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-03-21 17:50:29 -05:00
Preact: Keyboard shortcut to jump to next unread room (#2601)
This commit is contained in:
parent
df969fceb6
commit
ddfd9034a8
|
|
@ -2405,6 +2405,21 @@ export const PS = new class extends PSModel {
|
|||
}
|
||||
return this.focusRoom(rooms[index + 1]);
|
||||
}
|
||||
focusUnreadRoom(direction: 'left' | 'right') {
|
||||
const { rooms, index } = this.horizontalNav();
|
||||
if (index === -1) return;
|
||||
|
||||
const unreadRooms = rooms.filter((room, i) =>
|
||||
PS.rooms[room]?.isSubtleNotifying &&
|
||||
(direction === 'left' ? i < index : i > index)
|
||||
);
|
||||
|
||||
if (!unreadRooms.length) return;
|
||||
|
||||
const target = direction === 'left' ? unreadRooms[unreadRooms.length - 1] : unreadRooms[0];
|
||||
|
||||
return this.focusRoom(target);
|
||||
}
|
||||
alert(message: string, opts: { okButton?: string, parentElem?: HTMLElement | null, width?: number } = {}) {
|
||||
this.join(`popup-${this.popups.length}` as RoomID, {
|
||||
args: { message, ...opts, parentElem: null },
|
||||
|
|
|
|||
|
|
@ -934,6 +934,7 @@ export class ChatTextEntry extends preact.Component<{
|
|||
}
|
||||
handleKey(ev: KeyboardEvent) {
|
||||
const cmdKey = ((ev.metaKey ? 1 : 0) + (ev.ctrlKey ? 1 : 0) === 1) && !ev.altKey && !ev.shiftKey;
|
||||
const altKey = ev.altKey;
|
||||
// const anyModifier = ev.ctrlKey || ev.altKey || ev.metaKey || ev.shiftKey;
|
||||
if (ev.keyCode === 13 && !ev.shiftKey) { // Enter key
|
||||
return this.submit();
|
||||
|
|
@ -965,7 +966,7 @@ export class ChatTextEntry extends preact.Component<{
|
|||
// const newValue = `/pm ${PS.user.lastPM}, `;
|
||||
// this.setValue(newValue, newValue.length);
|
||||
// return true;
|
||||
} else if (ev.shiftKey && ev.keyCode === 37) {
|
||||
} else if (ev.shiftKey && ev.keyCode === 37 && !altKey) {
|
||||
if (PS.prefs.onepanel === 'vertical' || this.getValue().length > 0) return;
|
||||
const curLoc = PS.room.location;
|
||||
let newLoc = curLoc;
|
||||
|
|
@ -1002,7 +1003,7 @@ export class ChatTextEntry extends preact.Component<{
|
|||
PS.update();
|
||||
}
|
||||
return true;
|
||||
} else if (ev.shiftKey && ev.keyCode === 39) {
|
||||
} else if (ev.shiftKey && ev.keyCode === 39 && !altKey) {
|
||||
if (PS.prefs.onepanel === 'vertical' || this.getValue().length > 0) return;
|
||||
const curLoc = PS.room.location;
|
||||
let newLoc = curLoc;
|
||||
|
|
|
|||
|
|
@ -542,6 +542,13 @@ export class PSView extends preact.Component {
|
|||
}
|
||||
const modifierKey = ev.ctrlKey || ev.altKey || ev.metaKey || ev.shiftKey;
|
||||
const altKey = !ev.ctrlKey && ev.altKey && !ev.metaKey && !ev.shiftKey;
|
||||
if (ev.altKey && ev.shiftKey && ev.keyCode === 37) { // alt + shift + left
|
||||
PS.arrowKeysUsed = true;
|
||||
PS.focusUnreadRoom('left');
|
||||
} else if (ev.altKey && ev.shiftKey && ev.keyCode === 39) { // alt + shift + right
|
||||
PS.arrowKeysUsed = true;
|
||||
PS.focusUnreadRoom('right');
|
||||
}
|
||||
if (altKey && ev.keyCode === 38) { // alt + up
|
||||
PS.arrowKeysUsed = true;
|
||||
PS.focusUpRoom();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user