2021-03-07 07:05:36 +01:00
|
|
|
/*
|
|
|
|
Copyright 2021 Clemens Zeidler
|
2022-01-31 16:55:45 +01:00
|
|
|
Copyright 2022 Šimon Brandner <simon.bra.ag@gmail.com>
|
2021-03-07 07:05:36 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2022-01-31 16:55:45 +01:00
|
|
|
import { isMac, Key } from "./Keyboard";
|
|
|
|
import SettingsStore from "./settings/SettingsStore";
|
|
|
|
import SdkConfig from "./SdkConfig";
|
2021-12-07 10:32:00 +01:00
|
|
|
import {
|
|
|
|
IKeyBindingsProvider,
|
|
|
|
KeyBinding,
|
2022-01-31 16:55:45 +01:00
|
|
|
KeyCombo,
|
2021-12-07 10:32:00 +01:00
|
|
|
} from "./KeyBindingsManager";
|
2022-01-31 16:55:45 +01:00
|
|
|
import {
|
|
|
|
CATEGORIES,
|
|
|
|
CategoryName,
|
|
|
|
getCustomizableShortcuts,
|
|
|
|
KeyBindingAction,
|
|
|
|
} from "./accessibility/KeyboardShortcuts";
|
|
|
|
|
|
|
|
export const getBindingsByCategory = (
|
|
|
|
category: CategoryName,
|
|
|
|
): KeyBinding[] => {
|
|
|
|
return CATEGORIES[category].settingNames.reduce((bindings, name) => {
|
|
|
|
const value = getCustomizableShortcuts()[name]?.default;
|
|
|
|
if (value) {
|
|
|
|
bindings.push({
|
|
|
|
action: name as KeyBindingAction,
|
|
|
|
keyCombo: value as KeyCombo,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return bindings;
|
|
|
|
}, []);
|
|
|
|
};
|
|
|
|
|
|
|
|
const messageComposerBindings = (): KeyBinding[] => {
|
|
|
|
const bindings = getBindingsByCategory(CategoryName.COMPOSER);
|
2021-03-01 10:16:05 +01:00
|
|
|
|
|
|
|
if (SettingsStore.getValue('MessageComposerInput.ctrlEnterToSend')) {
|
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.SendMessage,
|
2021-03-01 10:16:05 +01:00
|
|
|
keyCombo: {
|
|
|
|
key: Key.ENTER,
|
2022-01-31 16:55:45 +01:00
|
|
|
ctrlOrCmdKey: true,
|
2021-03-01 10:16:05 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.NewLine,
|
2021-03-01 10:16:05 +01: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 10:16:05 +01:00
|
|
|
} else {
|
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.SendMessage,
|
2021-03-01 10:16:05 +01:00
|
|
|
keyCombo: {
|
|
|
|
key: Key.ENTER,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.NewLine,
|
2021-03-01 10:16:05 +01:00
|
|
|
keyCombo: {
|
|
|
|
key: Key.ENTER,
|
|
|
|
shiftKey: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (isMac) {
|
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.NewLine,
|
2021-03-01 10:16:05 +01:00
|
|
|
keyCombo: {
|
|
|
|
key: Key.ENTER,
|
|
|
|
altKey: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-01-31 16:55:45 +01:00
|
|
|
|
2021-03-01 10:16:05 +01:00
|
|
|
return bindings;
|
2021-06-29 14:11:58 +02:00
|
|
|
};
|
2021-03-01 10:16:05 +01: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 14:11:58 +02:00
|
|
|
};
|
2021-03-01 10:16:05 +01:00
|
|
|
|
2022-01-31 16:55:45 +01:00
|
|
|
const roomListBindings = (): KeyBinding[] => {
|
|
|
|
return getBindingsByCategory(CategoryName.ROOM_LIST);
|
2021-06-29 14:11:58 +02:00
|
|
|
};
|
2021-03-01 10:16:05 +01:00
|
|
|
|
2022-01-31 16:55:45 +01:00
|
|
|
const roomBindings = (): KeyBinding[] => {
|
|
|
|
const bindings = getBindingsByCategory(CategoryName.ROOM);
|
2021-03-01 10:16:05 +01:00
|
|
|
|
|
|
|
if (SettingsStore.getValue('ctrlFForSearch')) {
|
|
|
|
bindings.push({
|
2022-01-31 16:55:45 +01:00
|
|
|
action: KeyBindingAction.SearchInRoom,
|
2021-03-01 10:16:05 +01:00
|
|
|
keyCombo: {
|
|
|
|
key: Key.F,
|
2022-01-31 16:55:45 +01:00
|
|
|
ctrlOrCmdKey: true,
|
2021-03-01 10:16:05 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return bindings;
|
2021-06-29 14:11:58 +02:00
|
|
|
};
|
2021-03-01 10:16:05 +01:00
|
|
|
|
2022-01-31 16:55:45 +01:00
|
|
|
const navigationBindings = (): KeyBinding[] => {
|
|
|
|
return getBindingsByCategory(CategoryName.NAVIGATION);
|
2021-06-29 14:11:58 +02:00
|
|
|
};
|
2021-03-01 10:16:05 +01:00
|
|
|
|
2022-01-31 16:55:45 +01:00
|
|
|
const labsBindings = (): KeyBinding[] => {
|
|
|
|
if (!SdkConfig.get()['showLabsSettings']) 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 10:02:18 +01:00
|
|
|
export const defaultBindingsProvider: IKeyBindingsProvider = {
|
2021-03-01 10:16:05 +01:00
|
|
|
getMessageComposerBindings: messageComposerBindings,
|
|
|
|
getAutocompleteBindings: autocompleteBindings,
|
|
|
|
getRoomListBindings: roomListBindings,
|
|
|
|
getRoomBindings: roomBindings,
|
|
|
|
getNavigationBindings: navigationBindings,
|
2022-01-26 17:50:47 +01:00
|
|
|
getLabsBindings: labsBindings,
|
2021-06-29 14:11:58 +02:00
|
|
|
};
|