2021-03-07 19:05:36 +13:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-01-31 16:55:45 +01:00
|
|
|
Copyright 2022 Šimon Brandner <simon.bra.ag@gmail.com>
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2021 Clemens Zeidler
|
2021-03-07 19:05:36 +13:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2021-03-07 19:05:36 +13:00
|
|
|
*/
|
|
|
|
|
|
2022-05-03 22:04:37 +01:00
|
|
|
import { IS_MAC, Key } from "./Keyboard";
|
2022-01-31 16:55:45 +01:00
|
|
|
import SettingsStore from "./settings/SettingsStore";
|
|
|
|
|
import SdkConfig from "./SdkConfig";
|
2025-02-05 13:25:06 +00:00
|
|
|
import { type IKeyBindingsProvider, type KeyBinding } from "./KeyBindingsManager";
|
2022-01-31 16:55:45 +01:00
|
|
|
import { CATEGORIES, CategoryName, KeyBindingAction } from "./accessibility/KeyboardShortcuts";
|
2022-03-14 14:25:51 +01:00
|
|
|
import { getKeyboardShortcuts } from "./accessibility/KeyboardShortcutUtils";
|
2022-01-31 16:55:45 +01:00
|
|
|
|
2022-02-21 18:56:55 +00:00
|
|
|
export const getBindingsByCategory = (category: CategoryName): KeyBinding[] => {
|
2023-03-07 13:19:18 +00:00
|
|
|
return CATEGORIES[category].settingNames.reduce<KeyBinding[]>((bindings, action) => {
|
2022-05-03 22:04:37 +01:00
|
|
|
const keyCombo = getKeyboardShortcuts()[action]?.default;
|
|
|
|
|
if (keyCombo) {
|
|
|
|
|
bindings.push({ action, keyCombo });
|
2022-01-31 16:55:45 +01:00
|
|
|
}
|
|
|
|
|
return bindings;
|
|
|
|
|
}, []);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const messageComposerBindings = (): KeyBinding[] => {
|
|
|
|
|
const bindings = getBindingsByCategory(CategoryName.COMPOSER);
|
2021-03-01 22:16:05 +13:00
|
|
|
|
|
|
|
|
if (SettingsStore.getValue("MessageComposerInput.ctrlEnterToSend")) {
|
|
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.SendMessage,
|
2021-03-01 22:16:05 +13:00
|
|
|
keyCombo: {
|
|
|
|
|
key: Key.ENTER,
|
2022-01-31 16:55:45 +01:00
|
|
|
ctrlOrCmdKey: true,
|
2021-03-01 22:16:05 +13:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.NewLine,
|
2021-03-01 22:16:05 +13:00
|
|
|
keyCombo: {
|
|
|
|
|
key: Key.ENTER,
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-01-28 16:32:30 +01:00
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.NewLine,
|
2022-01-28 16:32:30 +01:00
|
|
|
keyCombo: {
|
|
|
|
|
key: Key.ENTER,
|
|
|
|
|
shiftKey: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
2021-03-01 22:16:05 +13:00
|
|
|
} else {
|
|
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.SendMessage,
|
2021-03-01 22:16:05 +13:00
|
|
|
keyCombo: {
|
|
|
|
|
key: Key.ENTER,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.NewLine,
|
2021-03-01 22:16:05 +13:00
|
|
|
keyCombo: {
|
|
|
|
|
key: Key.ENTER,
|
|
|
|
|
shiftKey: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-05-03 22:04:37 +01:00
|
|
|
if (IS_MAC) {
|
2021-03-01 22:16:05 +13:00
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.NewLine,
|
2021-03-01 22:16:05 +13:00
|
|
|
keyCombo: {
|
|
|
|
|
key: Key.ENTER,
|
|
|
|
|
altKey: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-31 16:55:45 +01:00
|
|
|
|
2021-03-01 22:16:05 +13:00
|
|
|
return bindings;
|
2021-06-29 13:11:58 +01:00
|
|
|
};
|
2021-03-01 22:16:05 +13:00
|
|
|
|
2022-01-31 16:55:45 +01:00
|
|
|
const autocompleteBindings = (): KeyBinding[] => {
|
|
|
|
|
const bindings = getBindingsByCategory(CategoryName.AUTOCOMPLETE);
|
|
|
|
|
|
|
|
|
|
bindings.push({
|
|
|
|
|
action: KeyBindingAction.ForceCompleteAutocomplete,
|
|
|
|
|
keyCombo: {
|
|
|
|
|
key: Key.TAB,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
bindings.push({
|
|
|
|
|
action: KeyBindingAction.ForceCompleteAutocomplete,
|
|
|
|
|
keyCombo: {
|
|
|
|
|
key: Key.TAB,
|
|
|
|
|
ctrlKey: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
bindings.push({
|
|
|
|
|
action: KeyBindingAction.CompleteAutocomplete,
|
|
|
|
|
keyCombo: {
|
|
|
|
|
key: Key.ENTER,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
bindings.push({
|
|
|
|
|
action: KeyBindingAction.CompleteAutocomplete,
|
|
|
|
|
keyCombo: {
|
|
|
|
|
key: Key.ENTER,
|
|
|
|
|
ctrlKey: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return bindings;
|
2021-06-29 13:11:58 +01:00
|
|
|
};
|
2021-03-01 22:16:05 +13:00
|
|
|
|
2022-01-31 16:55:45 +01:00
|
|
|
const roomListBindings = (): KeyBinding[] => {
|
|
|
|
|
return getBindingsByCategory(CategoryName.ROOM_LIST);
|
2021-06-29 13:11:58 +01:00
|
|
|
};
|
2021-03-01 22:16:05 +13:00
|
|
|
|
2022-01-31 16:55:45 +01:00
|
|
|
const roomBindings = (): KeyBinding[] => {
|
|
|
|
|
const bindings = getBindingsByCategory(CategoryName.ROOM);
|
2021-03-01 22:16:05 +13:00
|
|
|
|
|
|
|
|
if (SettingsStore.getValue("ctrlFForSearch")) {
|
|
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.SearchInRoom,
|
2021-03-01 22:16:05 +13:00
|
|
|
keyCombo: {
|
|
|
|
|
key: Key.F,
|
2022-01-31 16:55:45 +01:00
|
|
|
ctrlOrCmdKey: true,
|
2021-03-01 22:16:05 +13:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bindings;
|
2021-06-29 13:11:58 +01:00
|
|
|
};
|
2021-03-01 22:16:05 +13:00
|
|
|
|
2022-01-31 16:55:45 +01:00
|
|
|
const navigationBindings = (): KeyBinding[] => {
|
2022-02-28 17:05:52 +01:00
|
|
|
return getBindingsByCategory(CategoryName.NAVIGATION);
|
|
|
|
|
};
|
2022-02-21 18:56:55 +00:00
|
|
|
|
2022-02-28 17:05:52 +01:00
|
|
|
const accessibilityBindings = (): KeyBinding[] => {
|
|
|
|
|
return getBindingsByCategory(CategoryName.ACCESSIBILITY);
|
2021-06-29 13:11:58 +01:00
|
|
|
};
|
2021-03-01 22:16:05 +13:00
|
|
|
|
2022-02-23 10:12:04 +01:00
|
|
|
const callBindings = (): KeyBinding[] => {
|
|
|
|
|
return getBindingsByCategory(CategoryName.CALLS);
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-31 16:55:45 +01:00
|
|
|
const labsBindings = (): KeyBinding[] => {
|
2022-03-18 10:12:36 -06:00
|
|
|
if (!SdkConfig.get("show_labs_settings")) return [];
|
2022-01-26 17:50:47 +01:00
|
|
|
|
2022-01-31 16:55:45 +01:00
|
|
|
return getBindingsByCategory(CategoryName.LABS);
|
2022-01-26 17:50:47 +01:00
|
|
|
};
|
|
|
|
|
|
2021-03-05 22:02:18 +13:00
|
|
|
export const defaultBindingsProvider: IKeyBindingsProvider = {
|
2021-03-01 22:16:05 +13:00
|
|
|
getMessageComposerBindings: messageComposerBindings,
|
|
|
|
|
getAutocompleteBindings: autocompleteBindings,
|
|
|
|
|
getRoomListBindings: roomListBindings,
|
|
|
|
|
getRoomBindings: roomBindings,
|
|
|
|
|
getNavigationBindings: navigationBindings,
|
2022-02-28 17:05:52 +01:00
|
|
|
getAccessibilityBindings: accessibilityBindings,
|
2022-02-23 10:12:04 +01:00
|
|
|
getCallBindings: callBindings,
|
2022-01-26 17:50:47 +01:00
|
|
|
getLabsBindings: labsBindings,
|
2021-06-29 13:11:58 +01:00
|
|
|
};
|