Skip to content

Commit 75d6969

Browse files
authored
Merge pull request #107 from firai/del-search-box-bindings
Fix search box `Esc` bindings
2 parents 81ce68a + 36294d8 commit 75d6969

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

schema/plugin.json

+2-12
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,12 @@
1818
{
1919
"command": "documentsearch:end",
2020
"keys": ["Escape"],
21-
"selector": ".jp-mod-searchable .jp-FileEditor .cm-vimMode"
21+
"selector": ".jp-mod-searchable .jp-FileEditor [data-jp-vim-mode-name='normal']"
2222
},
2323
{
2424
"command": "documentsearch:end",
2525
"keys": ["Escape"],
26-
"selector": ".jp-mod-searchable .jp-Notebook .cm-vimMode"
27-
},
28-
{
29-
"command": "documentsearch:end",
30-
"keys": ["Escape"],
31-
"selector": ".jp-mod-search-active .jp-FileEditor .cm-vimMode"
32-
},
33-
{
34-
"command": "documentsearch:end",
35-
"keys": ["Escape"],
36-
"selector": ".jp-mod-search-active .jp-Notebook .cm-vimMode"
26+
"selector": ".jp-mod-search-active .jp-FileEditor [data-jp-vim-mode-name='normal']"
3727
},
3828
{
3929
"selector": ".jp-NotebookPanel[data-jp-vim-mode='true'] .jp-Notebook.jp-mod-editMode",

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)