Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove duplicated shortcuts (#12122)
* Remove duplicated shortcuts Fixes #12103 * Allow both Cmd + Enter and Ctrl + Enter on MacOS * Set shortcut on OS bases for `notebook:run-cell` * Fix for non-macOS * Restore two entries for run cell command * Remove shortcuts with `Cmd` on non Mac platform * Add unit tests * Update packages/settingregistry/src/tokens.ts Co-authored-by: Jason Grout <jasongrout@users.noreply.github.com> * Fix integrity and prettify * Explicitly use mac-specific key bindings, rather than relying on new implicit behavior Co-authored-by: Jason Grout <jasongrout@users.noreply.github.com> Co-authored-by: Jason Grout <jason@jasongrout.org>
- Loading branch information
1 parent
e89ba66
commit f64fed3
Showing
11 changed files
with
283 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "attach", | ||
"name": "Attach to jest", | ||
// Usage: | ||
// Open the parent directory in VSCode | ||
// Run `jlpm test:debug:watch` in a terminal | ||
// Run this debugging task | ||
"port": 9229 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@jupyterlab/testutils/lib/babel.config'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const func = require('@jupyterlab/testutils/lib/jest-config'); | ||
module.exports = func(__dirname); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
import { ISettingRegistry, SettingRegistry } from '@jupyterlab/settingregistry'; | ||
import * as plugin from '@jupyterlab/shortcuts-extension'; | ||
import { IDataConnector } from '@jupyterlab/statedb'; | ||
import { CommandRegistry } from '@lumino/commands'; | ||
import { Platform } from '@lumino/domutils'; | ||
import pluginSchema from '../schema/shortcuts.json'; | ||
|
||
describe('@jupyterlab/shortcut-extension', () => { | ||
const pluginId = 'test-plugin:settings'; | ||
|
||
let dummySettings: ISettingRegistry.IPlugin; | ||
|
||
beforeEach(() => { | ||
dummySettings = { | ||
data: { | ||
composite: {}, | ||
user: {} | ||
}, | ||
id: plugin.default.id, | ||
raw: '{}', | ||
schema: pluginSchema as any, | ||
version: 'test' | ||
}; | ||
}); | ||
|
||
describe('shorcuts list', () => { | ||
it('should ignored Cmd on non-Mac platform', async () => { | ||
const bar: ISettingRegistry.IPlugin = { | ||
data: { | ||
composite: {}, | ||
user: {} | ||
}, | ||
id: pluginId, | ||
raw: '{}', | ||
schema: { | ||
'jupyter.lab.shortcuts': [ | ||
{ | ||
command: 'notebook:run-cell', | ||
keys: ['Ctrl Enter'], | ||
selector: '.jp-Notebook.jp-mod-editMode' | ||
}, | ||
{ | ||
command: 'notebook:run-cell', | ||
keys: ['Cmd Enter'], | ||
selector: '.jp-Notebook.jp-mod-editMode' | ||
} | ||
], | ||
type: 'object' | ||
}, | ||
version: 'test' | ||
}; | ||
|
||
const connector: IDataConnector< | ||
ISettingRegistry.IPlugin, | ||
string, | ||
string, | ||
string | ||
> = { | ||
fetch: jest.fn().mockImplementation((id: string) => { | ||
switch (id) { | ||
case bar.id: | ||
return bar; | ||
case plugin.default.id: | ||
return dummySettings; | ||
default: | ||
return {}; | ||
} | ||
}), | ||
list: jest.fn(), | ||
save: jest.fn(), | ||
remove: jest.fn() | ||
}; | ||
|
||
const settingRegistry = new SettingRegistry({ | ||
connector, | ||
timeout: Infinity | ||
}); | ||
|
||
await settingRegistry.load(bar.id); | ||
|
||
plugin.default.activate( | ||
{ | ||
commands: new CommandRegistry() | ||
} as any, | ||
settingRegistry | ||
); | ||
|
||
const settings = await settingRegistry.load(plugin.default.id); | ||
const shortcuts = (await settings.get('shortcuts') | ||
.composite) as ISettingRegistry.IShortcut[]; | ||
|
||
expect(shortcuts).toHaveLength(Platform.IS_MAC ? 2 : 1); | ||
}); | ||
|
||
it('should ignore colliding shortcuts', async () => { | ||
const pluginId = 'test-plugin:settings'; | ||
const bar: ISettingRegistry.IPlugin = { | ||
data: { | ||
composite: {}, | ||
user: {} | ||
}, | ||
id: pluginId, | ||
raw: '{}', | ||
schema: { | ||
'jupyter.lab.shortcuts': [ | ||
{ | ||
command: 'notebook:run-cell', | ||
keys: ['Accel Enter'], | ||
selector: '.jp-Notebook.jp-mod-editMode' | ||
}, | ||
{ | ||
command: 'another-colliding-command', | ||
keys: ['Accel Enter'], | ||
selector: '.jp-Notebook.jp-mod-editMode' | ||
} | ||
], | ||
type: 'object' | ||
}, | ||
version: 'test' | ||
}; | ||
|
||
const connector: IDataConnector< | ||
ISettingRegistry.IPlugin, | ||
string, | ||
string, | ||
string | ||
> = { | ||
fetch: jest.fn().mockImplementation((id: string) => { | ||
switch (id) { | ||
case bar.id: | ||
return bar; | ||
case plugin.default.id: | ||
return dummySettings; | ||
default: | ||
return {}; | ||
} | ||
}), | ||
list: jest.fn(), | ||
save: jest.fn(), | ||
remove: jest.fn() | ||
}; | ||
|
||
const settingRegistry = new SettingRegistry({ | ||
connector | ||
}); | ||
|
||
await settingRegistry.load(bar.id); | ||
|
||
plugin.default.activate( | ||
{ | ||
commands: new CommandRegistry() | ||
} as any, | ||
settingRegistry | ||
); | ||
|
||
const settings = await settingRegistry.load(plugin.default.id); | ||
const shortcuts = (await settings.get('shortcuts') | ||
.composite) as ISettingRegistry.IShortcut[]; | ||
|
||
expect(shortcuts).toHaveLength(1); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.