Skip to content

Commit

Permalink
Resetting a shortcut does not restore and enable the default if it wa…
Browse files Browse the repository at this point in the history
…s modified (#16304)

* Fix for shortcut disabled on reset

* Added test
  • Loading branch information
itsmevichu committed May 9, 2024
1 parent 3c13610 commit 66bc3b0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/shortcuts-extension/src/components/ShortcutUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ export class ShortcutUI
});
}
found = true;
} else if (
keybinding &&
!JSONExt.deepEqual(keybinding.keys, shortcut.keys) &&
keys.length === 0
) {
continue;
} else {
newUserShortcuts.push(shortcut);
}
Expand Down
42 changes: 42 additions & 0 deletions packages/shortcuts-extension/test/components/ShortcutUI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,48 @@ describe('@jupyterlab/shortcut-extension', () => {
expect(data.user.shortcuts).toHaveLength(0);
});

it('should reset default overrides for given shortcut target', async () => {
const defaultKeybinding = {
keys: ['Ctrl A'],
isDefault: true
};

const replacedKeybinding = {
keys: ['Ctrl D'],
isDefault: false
};
const target = {
id: 'test-id',
command: 'test:command',
keybindings: [defaultKeybinding],
args: {},
selector: 'body',
category: 'test'
};
registerKeybinding(target, defaultKeybinding);
await shortcutUI.replaceKeybinding(target, defaultKeybinding, [
'Ctrl D'
]);

//update the target to the new keybinding.
target.keybindings = [replacedKeybinding];

expect(data.user.shortcuts).toHaveLength(2);
expect(data.user.shortcuts[0]).toEqual({
command: 'test:command',
keys: ['Ctrl A'],
selector: 'body',
disabled: true
});
expect(data.user.shortcuts[1]).toEqual({
command: 'test:command',
keys: ['Ctrl D'],
selector: 'body'
});
await shortcutUI.resetKeybindings(target);
expect(data.user.shortcuts).toHaveLength(0);
});

it('should clear defaults overrides for given shortcut target', async () => {
const keybinding = {
keys: ['Ctrl A'],
Expand Down

0 comments on commit 66bc3b0

Please sign in to comment.