Initial hotkeys for frontend
parent
36a67a2ca1
commit
1f82842293
|
@ -36,6 +36,8 @@ export class MainView extends View {
|
||||||
|
|
||||||
private messageElementMap: Map<number, UINode> = new Map();
|
private messageElementMap: Map<number, UINode> = new Map();
|
||||||
|
|
||||||
|
private hotkeyMap: Map<string, () => void> = new Map();
|
||||||
|
|
||||||
public onActivate(): void {
|
public onActivate(): void {
|
||||||
if (!state.currentChannel) {
|
if (!state.currentChannel) {
|
||||||
if (state.defaultChannelId) {
|
if (state.defaultChannelId) {
|
||||||
|
@ -71,11 +73,14 @@ export class MainView extends View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
document.addEventListener("keydown", (e) => this.handleHotkey(e));
|
||||||
|
}
|
||||||
|
|
||||||
public onDeactivate(): void {
|
public onDeactivate(): void {
|
||||||
clearInterval(this.updateInterval);
|
clearInterval(this.updateInterval);
|
||||||
|
// unregister hotkey
|
||||||
|
document.removeEventListener("keydown", (e) => this.handleHotkey(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
public onCreate(): void {
|
public onCreate(): void {
|
||||||
|
@ -124,6 +129,7 @@ export class MainView extends View {
|
||||||
});
|
});
|
||||||
this.channelInfoButton.onClick(() => this.handleChannelInfoButton());
|
this.channelInfoButton.onClick(() => this.handleChannelInfoButton());
|
||||||
this.imageInput.onClick(async () => this.handleImageButton());
|
this.imageInput.onClick(async () => this.handleImageButton());
|
||||||
|
this.setHotkeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
public onDestroy(): void {
|
public onDestroy(): void {
|
||||||
|
@ -564,4 +570,23 @@ export class MainView extends View {
|
||||||
const photo = await new TakePhotoDialog().open();
|
const photo = await new TakePhotoDialog().open();
|
||||||
this.uploadImage(photo);
|
this.uploadImage(photo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setHotkeys() {
|
||||||
|
this.hotkeyMap.set("s", () => this.openSettingsDialog());
|
||||||
|
this.hotkeyMap.set("c", () => this.channelSwitcher.focus());
|
||||||
|
this.hotkeyMap.set("x", () => this.handleChannelInfoButton());
|
||||||
|
this.hotkeyMap.set("f", () => this.openSearchDialog());
|
||||||
|
this.hotkeyMap.set("v", () => this.handleVoiceMessageButton());
|
||||||
|
this.hotkeyMap.set(" ", () => this.messageInput.focus());
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleHotkey(e: KeyboardEvent) {
|
||||||
|
if (e.altKey) {
|
||||||
|
const action = this.hotkeyMap.get(e.key);
|
||||||
|
if (action) {
|
||||||
|
e.preventDefault();
|
||||||
|
action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue