2021-03-07 06:05:36 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 Clemens Zeidler
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-12-07 09:32:00 +00:00
|
|
|
import {
|
|
|
|
AutocompleteAction,
|
|
|
|
IKeyBindingsProvider,
|
|
|
|
KeyBinding,
|
|
|
|
MessageComposerAction,
|
|
|
|
NavigationAction,
|
|
|
|
RoomAction,
|
|
|
|
RoomListAction,
|
2022-01-26 16:50:47 +00:00
|
|
|
LabsAction,
|
2021-12-07 09:32:00 +00:00
|
|
|
} from "./KeyBindingsManager";
|
2021-03-01 09:16:05 +00:00
|
|
|
import { isMac, Key } from "./Keyboard";
|
|
|
|
import SettingsStore from "./settings/SettingsStore";
|
2022-01-26 16:50:47 +00:00
|
|
|
import SdkConfig from "./SdkConfig";
|
2021-03-01 09:16:05 +00:00
|
|
|
|
|
|
|
const messageComposerBindings = (): KeyBinding<MessageComposerAction>[] => {
|
|
|
|
const bindings: KeyBinding<MessageComposerAction>[] = [
|
|
|
|
{
|
|
|
|
action: MessageComposerAction.SelectPrevSendHistory,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_UP,
|
|
|
|
altKey: true,
|
|
|
|
ctrlKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: MessageComposerAction.SelectNextSendHistory,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_DOWN,
|
|
|
|
altKey: true,
|
|
|
|
ctrlKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: MessageComposerAction.EditPrevMessage,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_UP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: MessageComposerAction.EditNextMessage,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_DOWN,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: MessageComposerAction.CancelEditing,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ESCAPE,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: MessageComposerAction.FormatBold,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.B,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: MessageComposerAction.FormatItalics,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.I,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: MessageComposerAction.FormatQuote,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.GREATER_THAN,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
shiftKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: MessageComposerAction.EditUndo,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.Z,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: MessageComposerAction.MoveCursorToStart,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.HOME,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: MessageComposerAction.MoveCursorToEnd,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.END,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
if (isMac) {
|
|
|
|
bindings.push({
|
|
|
|
action: MessageComposerAction.EditRedo,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.Z,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
shiftKey: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
bindings.push({
|
|
|
|
action: MessageComposerAction.EditRedo,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.Y,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (SettingsStore.getValue('MessageComposerInput.ctrlEnterToSend')) {
|
|
|
|
bindings.push({
|
|
|
|
action: MessageComposerAction.Send,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ENTER,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
bindings.push({
|
|
|
|
action: MessageComposerAction.NewLine,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ENTER,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
bindings.push({
|
|
|
|
action: MessageComposerAction.Send,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ENTER,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
bindings.push({
|
|
|
|
action: MessageComposerAction.NewLine,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ENTER,
|
|
|
|
shiftKey: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (isMac) {
|
|
|
|
bindings.push({
|
|
|
|
action: MessageComposerAction.NewLine,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ENTER,
|
|
|
|
altKey: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bindings;
|
2021-06-29 12:11:58 +00:00
|
|
|
};
|
2021-03-01 09:16:05 +00:00
|
|
|
|
|
|
|
const autocompleteBindings = (): KeyBinding<AutocompleteAction>[] => {
|
|
|
|
return [
|
|
|
|
{
|
2021-05-11 10:14:21 +00:00
|
|
|
action: AutocompleteAction.ForceComplete,
|
2021-03-01 09:16:05 +00:00
|
|
|
keyCombo: {
|
|
|
|
key: Key.TAB,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-05-11 10:14:21 +00:00
|
|
|
action: AutocompleteAction.ForceComplete,
|
2021-03-01 09:16:05 +00:00
|
|
|
keyCombo: {
|
|
|
|
key: Key.TAB,
|
|
|
|
ctrlKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-05-11 10:14:21 +00:00
|
|
|
action: AutocompleteAction.Complete,
|
2021-03-01 09:16:05 +00:00
|
|
|
keyCombo: {
|
2021-05-11 10:14:21 +00:00
|
|
|
key: Key.ENTER,
|
2021-03-01 09:16:05 +00:00
|
|
|
},
|
|
|
|
},
|
2021-03-03 09:07:44 +00:00
|
|
|
{
|
2021-05-11 10:14:21 +00:00
|
|
|
action: AutocompleteAction.Complete,
|
2021-03-03 09:07:44 +00:00
|
|
|
keyCombo: {
|
2021-05-11 10:14:21 +00:00
|
|
|
key: Key.ENTER,
|
2021-03-03 09:07:44 +00:00
|
|
|
ctrlKey: true,
|
|
|
|
},
|
|
|
|
},
|
2021-03-01 09:16:05 +00:00
|
|
|
{
|
|
|
|
action: AutocompleteAction.Cancel,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ESCAPE,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: AutocompleteAction.PrevSelection,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_UP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: AutocompleteAction.NextSelection,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_DOWN,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
2021-06-29 12:11:58 +00:00
|
|
|
};
|
2021-03-01 09:16:05 +00:00
|
|
|
|
|
|
|
const roomListBindings = (): KeyBinding<RoomListAction>[] => {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
action: RoomListAction.ClearSearch,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ESCAPE,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: RoomListAction.PrevRoom,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_UP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: RoomListAction.NextRoom,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_DOWN,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: RoomListAction.SelectRoom,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ENTER,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: RoomListAction.CollapseSection,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_LEFT,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: RoomListAction.ExpandSection,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_RIGHT,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
2021-06-29 12:11:58 +00:00
|
|
|
};
|
2021-03-01 09:16:05 +00:00
|
|
|
|
|
|
|
const roomBindings = (): KeyBinding<RoomAction>[] => {
|
2021-03-12 06:40:28 +00:00
|
|
|
const bindings: KeyBinding<RoomAction>[] = [
|
2021-03-01 09:16:05 +00:00
|
|
|
{
|
|
|
|
action: RoomAction.ScrollUp,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.PAGE_UP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: RoomAction.RoomScrollDown,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.PAGE_DOWN,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: RoomAction.DismissReadMarker,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ESCAPE,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: RoomAction.JumpToOldestUnread,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.PAGE_UP,
|
|
|
|
shiftKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: RoomAction.UploadFile,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.U,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
shiftKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: RoomAction.JumpToFirstMessage,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.HOME,
|
|
|
|
ctrlKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: RoomAction.JumpToLatestMessage,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.END,
|
|
|
|
ctrlKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
if (SettingsStore.getValue('ctrlFForSearch')) {
|
|
|
|
bindings.push({
|
|
|
|
action: RoomAction.FocusSearch,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.F,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return bindings;
|
2021-06-29 12:11:58 +00:00
|
|
|
};
|
2021-03-01 09:16:05 +00:00
|
|
|
|
|
|
|
const navigationBindings = (): KeyBinding<NavigationAction>[] => {
|
|
|
|
return [
|
2021-03-12 06:40:28 +00:00
|
|
|
{
|
|
|
|
action: NavigationAction.FocusRoomSearch,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.K,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
},
|
2021-12-07 09:32:00 +00:00
|
|
|
{
|
|
|
|
action: NavigationAction.ToggleSpacePanel,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.D,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
shiftKey: true,
|
|
|
|
},
|
|
|
|
},
|
2021-03-01 09:16:05 +00:00
|
|
|
{
|
|
|
|
action: NavigationAction.ToggleRoomSidePanel,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.PERIOD,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: NavigationAction.ToggleUserMenu,
|
|
|
|
// Ideally this would be CTRL+P for "Profile", but that's
|
|
|
|
// taken by the print dialog. CTRL+I for "Information"
|
|
|
|
// was previously chosen but conflicted with italics in
|
|
|
|
// composer, so CTRL+` it is
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.BACKTICK,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-01-17 11:53:10 +00:00
|
|
|
action: NavigationAction.OpenShortCutDialog,
|
2021-03-01 09:16:05 +00:00
|
|
|
keyCombo: {
|
|
|
|
key: Key.SLASH,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-01-17 11:53:10 +00:00
|
|
|
action: NavigationAction.OpenShortCutDialog,
|
2021-03-01 09:16:05 +00:00
|
|
|
keyCombo: {
|
|
|
|
key: Key.SLASH,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
shiftKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: NavigationAction.GoToHome,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.H,
|
2022-01-26 08:52:55 +00:00
|
|
|
ctrlOrCmd: true,
|
2021-03-30 18:00:12 +00:00
|
|
|
altKey: !isMac,
|
|
|
|
shiftKey: isMac,
|
2021-03-01 09:16:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: NavigationAction.SelectPrevRoom,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_UP,
|
|
|
|
altKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: NavigationAction.SelectNextRoom,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_DOWN,
|
|
|
|
altKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: NavigationAction.SelectPrevUnreadRoom,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_UP,
|
|
|
|
altKey: true,
|
|
|
|
shiftKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: NavigationAction.SelectNextUnreadRoom,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.ARROW_DOWN,
|
|
|
|
altKey: true,
|
|
|
|
shiftKey: true,
|
|
|
|
},
|
|
|
|
},
|
2021-03-12 06:40:28 +00:00
|
|
|
];
|
2021-06-29 12:11:58 +00:00
|
|
|
};
|
2021-03-01 09:16:05 +00:00
|
|
|
|
2022-01-26 16:50:47 +00:00
|
|
|
const labsBindings = (): KeyBinding<LabsAction>[] => {
|
|
|
|
if (!SdkConfig.get()['showLabsSettings']) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
action: LabsAction.ToggleHiddenEventVisibility,
|
|
|
|
keyCombo: {
|
|
|
|
key: Key.H,
|
|
|
|
ctrlOrCmd: true,
|
|
|
|
shiftKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2021-03-05 09:02:18 +00:00
|
|
|
export const defaultBindingsProvider: IKeyBindingsProvider = {
|
2021-03-01 09:16:05 +00:00
|
|
|
getMessageComposerBindings: messageComposerBindings,
|
|
|
|
getAutocompleteBindings: autocompleteBindings,
|
|
|
|
getRoomListBindings: roomListBindings,
|
|
|
|
getRoomBindings: roomBindings,
|
|
|
|
getNavigationBindings: navigationBindings,
|
2022-01-26 16:50:47 +00:00
|
|
|
getLabsBindings: labsBindings,
|
2021-06-29 12:11:58 +00:00
|
|
|
};
|