Skip to content

Commit 9161f81

Browse files
author
Ives van Hoorne
committed
Fix setting custom keybindings
Fixes codesandbox#707
1 parent 4ee8ed7 commit 9161f81

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

packages/app/src/app/store/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export function setStoredSettings({ state, settingsStore }) {
235235
}
236236

237237
export function setKeybindings({ state, keybindingManager }) {
238-
keybindingManager.set(state.get('preferences.settings.keybindings'));
238+
keybindingManager.set(state.get('preferences.settings.keybindings').toJSON());
239239
}
240240

241241
export function startKeybindings({ keybindingManager }) {

packages/app/src/app/store/providers/KeybindingManager.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,21 @@ let isStarted = false;
137137

138138
export default Provider({
139139
set(userKeybindings = []) {
140-
const keybindings = userKeybindings.concat(
141-
Object.keys(KEYBINDINGS).reduce(
142-
(currentKeybindings, key) =>
143-
currentKeybindings.concat({
144-
key,
145-
bindings: KEYBINDINGS[key].bindings,
146-
}),
147-
[]
148-
)
149-
);
140+
const keybindings = [...userKeybindings];
141+
142+
Object.keys(KEYBINDINGS).forEach(bindingName => {
143+
if (keybindings.find(x => x.key === bindingName)) {
144+
return;
145+
}
146+
147+
keybindings.push({
148+
key: bindingName,
149+
bindings: KEYBINDINGS[bindingName].bindings,
150+
});
151+
});
150152

151153
state.keybindings = keybindings.filter(
152-
binding => binding.bindings && binding.bindings.length
154+
binding => binding.bindings && binding.bindings.filter(Boolean).length
153155
);
154156
},
155157
start() {

0 commit comments

Comments
 (0)