Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyboard shortcuts editor in settings #1403

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/insomnia-app/app/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ export const ALT_SYM = isMac() ? '⌥' : 'Alt';
export const SHIFT_SYM = isMac() ? '⇧' : 'Shift';
export const META_SYM = isMac() ? '⌘' : 'Super';

export function joinHotKeys(keys) {
return keys.join(isMac() ? '' : '+');
}

// Updates
export const UPDATE_CHANNEL_STABLE = 'stable';
export const UPDATE_CHANNEL_BETA = 'beta';
Expand Down
39 changes: 11 additions & 28 deletions packages/insomnia-app/app/common/hotkeys-listener.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
// @flow
import type { HotKeyDefinition, KeyBindings } from './hotkeys';
import { getPlatformKeyCombinations } from './hotkeys';
import type { HotKeyDefinition, KeyBindings, KeyCombination } from './hotkeys';
import { areSameKeyCombinations, getPlatformKeyCombinations } from './hotkeys';
import * as models from '../models';

function _pressedHotKey(e: KeyboardEvent, bindings: KeyBindings): boolean {
const isCtrlPressed = e.ctrlKey;
const isAltPressed = e.altKey;
const isShiftPressed = e.shiftKey;
const isMetaPressed = e.metaKey;
const pressedKeyComb: KeyCombination = {
ctrl: e.ctrlKey,
alt: e.altKey,
shift: e.shiftKey,
meta: e.metaKey,
keyCode: e.keyCode,
};
const keyCombList = getPlatformKeyCombinations(bindings);

for (const keyComb of keyCombList) {
const { ctrl, alt, shift, meta, keyCode } = keyComb;

if ((ctrl && !isCtrlPressed) || (!ctrl && isCtrlPressed)) {
continue;
}

if ((alt && !isAltPressed) || (!alt && isAltPressed)) {
continue;
}

if ((shift && !isShiftPressed) || (!shift && isShiftPressed)) {
continue;
if (areSameKeyCombinations(pressedKeyComb, keyComb)) {
return true;
}

if ((meta && !isMetaPressed) || (!meta && isMetaPressed)) {
continue;
}

if (keyCode !== e.keyCode) {
continue;
}

return true;
}

return false;
Expand Down
Loading