mirror of
https://github.com/element-hq/element-web
synced 2024-11-26 03:05:51 +03:00
Only support a single key in the KeyCombo
Keep it simple...
This commit is contained in:
parent
b4c5dec4e5
commit
4a138f3b84
2 changed files with 17 additions and 18 deletions
|
@ -20,8 +20,7 @@ export enum KeyAction {
|
|||
* The combo is evaluated strictly, i.e. the KeyboardEvent must match exactly what is specified in the KeyCombo.
|
||||
*/
|
||||
export type KeyCombo = {
|
||||
/** Currently only one `normal` key is supported */
|
||||
keys: string[];
|
||||
key?: string;
|
||||
|
||||
/** On PC: ctrl is pressed; on Mac: meta is pressed */
|
||||
ctrlOrCmd?: boolean;
|
||||
|
@ -42,7 +41,7 @@ const messageComposerBindings = (): KeyBinding[] => {
|
|||
{
|
||||
action: KeyAction.SelectPrevSendHistory,
|
||||
keyCombo: {
|
||||
keys: [Key.ARROW_UP],
|
||||
key: Key.ARROW_UP,
|
||||
altKey: true,
|
||||
ctrlKey: true,
|
||||
},
|
||||
|
@ -50,7 +49,7 @@ const messageComposerBindings = (): KeyBinding[] => {
|
|||
{
|
||||
action: KeyAction.SelectNextSendHistory,
|
||||
keyCombo: {
|
||||
keys: [Key.ARROW_DOWN],
|
||||
key: Key.ARROW_DOWN,
|
||||
altKey: true,
|
||||
ctrlKey: true,
|
||||
},
|
||||
|
@ -58,7 +57,7 @@ const messageComposerBindings = (): KeyBinding[] => {
|
|||
{
|
||||
action: KeyAction.EditLastMessage,
|
||||
keyCombo: {
|
||||
keys: [Key.ARROW_UP],
|
||||
key: Key.ARROW_UP,
|
||||
}
|
||||
},
|
||||
];
|
||||
|
@ -66,7 +65,7 @@ const messageComposerBindings = (): KeyBinding[] => {
|
|||
bindings.push({
|
||||
action: KeyAction.Send,
|
||||
keyCombo: {
|
||||
keys: [Key.ENTER],
|
||||
key: Key.ENTER,
|
||||
ctrlOrCmd: true,
|
||||
},
|
||||
});
|
||||
|
@ -74,7 +73,7 @@ const messageComposerBindings = (): KeyBinding[] => {
|
|||
bindings.push({
|
||||
action: KeyAction.Send,
|
||||
keyCombo: {
|
||||
keys: [Key.ENTER],
|
||||
key: Key.ENTER,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -88,7 +87,7 @@ const messageComposerBindings = (): KeyBinding[] => {
|
|||
* Note, this method is only exported for testing.
|
||||
*/
|
||||
export function isKeyComboMatch(ev: KeyboardEvent, combo: KeyCombo, onMac: boolean): boolean {
|
||||
if (combo.keys.length > 0 && ev.key !== combo.keys[0]) {
|
||||
if (combo.key !== undefined && ev.key !== combo.key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ function mockKeyEvent(key: string, modifiers?: {
|
|||
describe('KeyBindingsManager', () => {
|
||||
it('should match basic key combo', () => {
|
||||
const combo1: KeyCombo = {
|
||||
keys: ['k'],
|
||||
key: 'k',
|
||||
};
|
||||
assert.strictEqual(isKeyComboMatch(mockKeyEvent('k'), combo1, false), true);
|
||||
assert.strictEqual(isKeyComboMatch(mockKeyEvent('n'), combo1, false), false);
|
||||
|
@ -28,7 +28,7 @@ describe('KeyBindingsManager', () => {
|
|||
|
||||
it('should match key + modifier key combo', () => {
|
||||
const combo: KeyCombo = {
|
||||
keys: ['k'],
|
||||
key: 'k',
|
||||
ctrlKey: true,
|
||||
};
|
||||
assert.strictEqual(isKeyComboMatch(mockKeyEvent('k', { ctrlKey: true }), combo, false), true);
|
||||
|
@ -38,7 +38,7 @@ describe('KeyBindingsManager', () => {
|
|||
assert.strictEqual(isKeyComboMatch(mockKeyEvent('k', { shiftKey: true, metaKey: true }), combo, false), false);
|
||||
|
||||
const combo2: KeyCombo = {
|
||||
keys: ['k'],
|
||||
key: 'k',
|
||||
metaKey: true,
|
||||
};
|
||||
assert.strictEqual(isKeyComboMatch(mockKeyEvent('k', { metaKey: true }), combo2, false), true);
|
||||
|
@ -47,7 +47,7 @@ describe('KeyBindingsManager', () => {
|
|||
assert.strictEqual(isKeyComboMatch(mockKeyEvent('k', { altKey: true, metaKey: true }), combo2, false), false);
|
||||
|
||||
const combo3: KeyCombo = {
|
||||
keys: ['k'],
|
||||
key: 'k',
|
||||
altKey: true,
|
||||
};
|
||||
assert.strictEqual(isKeyComboMatch(mockKeyEvent('k', { altKey: true }), combo3, false), true);
|
||||
|
@ -56,7 +56,7 @@ describe('KeyBindingsManager', () => {
|
|||
assert.strictEqual(isKeyComboMatch(mockKeyEvent('k', { ctrlKey: true, metaKey: true }), combo3, false), false);
|
||||
|
||||
const combo4: KeyCombo = {
|
||||
keys: ['k'],
|
||||
key: 'k',
|
||||
shiftKey: true,
|
||||
};
|
||||
assert.strictEqual(isKeyComboMatch(mockKeyEvent('k', { shiftKey: true }), combo4, false), true);
|
||||
|
@ -67,7 +67,7 @@ describe('KeyBindingsManager', () => {
|
|||
|
||||
it('should match key + multiple modifiers key combo', () => {
|
||||
const combo: KeyCombo = {
|
||||
keys: ['k'],
|
||||
key: 'k',
|
||||
ctrlKey: true,
|
||||
altKey: true,
|
||||
};
|
||||
|
@ -78,7 +78,7 @@ describe('KeyBindingsManager', () => {
|
|||
false), false);
|
||||
|
||||
const combo2: KeyCombo = {
|
||||
keys: ['k'],
|
||||
key: 'k',
|
||||
ctrlKey: true,
|
||||
shiftKey: true,
|
||||
altKey: true,
|
||||
|
@ -92,7 +92,7 @@ describe('KeyBindingsManager', () => {
|
|||
{ ctrlKey: true, shiftKey: true, altKey: true, metaKey: true }), combo2, false), false);
|
||||
|
||||
const combo3: KeyCombo = {
|
||||
keys: ['k'],
|
||||
key: 'k',
|
||||
ctrlKey: true,
|
||||
shiftKey: true,
|
||||
altKey: true,
|
||||
|
@ -108,7 +108,7 @@ describe('KeyBindingsManager', () => {
|
|||
|
||||
it('should match ctrlOrMeta key combo', () => {
|
||||
const combo: KeyCombo = {
|
||||
keys: ['k'],
|
||||
key: 'k',
|
||||
ctrlOrCmd: true,
|
||||
};
|
||||
// PC:
|
||||
|
@ -123,7 +123,7 @@ describe('KeyBindingsManager', () => {
|
|||
|
||||
it('should match advanced ctrlOrMeta key combo', () => {
|
||||
const combo: KeyCombo = {
|
||||
keys: ['k'],
|
||||
key: 'k',
|
||||
ctrlOrCmd: true,
|
||||
altKey: true,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue