Skip to content

Commit 36294d8

Browse files
committed
Restore the shortcut in file editor but only in normal mode
1 parent 5c2731e commit 36294d8

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

schema/plugin.json

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
"keys": ["Escape"],
1616
"selector": ".jp-FileEditor"
1717
},
18+
{
19+
"command": "documentsearch:end",
20+
"keys": ["Escape"],
21+
"selector": ".jp-mod-searchable .jp-FileEditor [data-jp-vim-mode-name='normal']"
22+
},
23+
{
24+
"command": "documentsearch:end",
25+
"keys": ["Escape"],
26+
"selector": ".jp-mod-search-active .jp-FileEditor [data-jp-vim-mode-name='normal']"
27+
},
1828
{
1929
"selector": ".jp-NotebookPanel[data-jp-vim-mode='true'] .jp-Notebook.jp-mod-editMode",
2030
"keys": ["Ctrl O", "U"],

src/codemirrorCommands.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@ export class VimEditorManager {
6767
this.modifyEditor(this._lastActiveEditor);
6868
}
6969

70+
/**
71+
* Hook up vim mode into given editor.
72+
* Returns true if vim mode was enabled.
73+
*/
7074
modifyEditor(editor: CodeEditor.IEditor | null): boolean {
71-
// JupyterLab 4.0 only supports CodeMirror editors
72-
const mirrorEditor = editor as CodeMirrorEditor | null;
73-
74-
if (!mirrorEditor) {
75+
if (!editor) {
7576
throw Error('Editor not available');
7677
}
78+
// JupyterLab 4.0 only supports CodeMirror editors
79+
const mirrorEditor = editor as CodeMirrorEditor;
80+
7781
this._lastActiveEditor = mirrorEditor;
7882

7983
const view = mirrorEditor.editor;
@@ -89,6 +93,9 @@ export class VimEditorManager {
8993
// as blurred because it exists outside of the CodeMirror6 state; here
9094
// we override `hasFocus` handler to ensure it is taken into account.
9195
const cm = getCM(view)!;
96+
cm.on('vim-mode-change', () => {
97+
editor.host.dataset.jpVimModeName = cm.state.vim.mode;
98+
});
9299
mirrorEditor.hasFocus = () => {
93100
if (
94101
cm.state.dialog &&

0 commit comments

Comments
 (0)