Skip to content

Fix search box Esc bindings #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions schema/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,12 @@
{
"command": "documentsearch:end",
"keys": ["Escape"],
"selector": ".jp-mod-searchable .jp-FileEditor .cm-vimMode"
"selector": ".jp-mod-searchable .jp-FileEditor [data-jp-vim-mode-name='normal']"
},
{
"command": "documentsearch:end",
"keys": ["Escape"],
"selector": ".jp-mod-searchable .jp-Notebook .cm-vimMode"
},
{
"command": "documentsearch:end",
"keys": ["Escape"],
"selector": ".jp-mod-search-active .jp-FileEditor .cm-vimMode"
},
{
"command": "documentsearch:end",
"keys": ["Escape"],
"selector": ".jp-mod-search-active .jp-Notebook .cm-vimMode"
"selector": ".jp-mod-search-active .jp-FileEditor [data-jp-vim-mode-name='normal']"
},
{
"selector": ".jp-NotebookPanel[data-jp-vim-mode='true'] .jp-Notebook.jp-mod-editMode",
Expand Down
15 changes: 11 additions & 4 deletions src/codemirrorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ export class VimEditorManager {
this.modifyEditor(this._lastActiveEditor);
}

/**
* Hook up vim mode into given editor.
* Returns true if vim mode was enabled.
*/
modifyEditor(editor: CodeEditor.IEditor | null): boolean {
// JupyterLab 4.0 only supports CodeMirror editors
const mirrorEditor = editor as CodeMirrorEditor | null;

if (!mirrorEditor) {
if (!editor) {
throw Error('Editor not available');
}
// JupyterLab 4.0 only supports CodeMirror editors
const mirrorEditor = editor as CodeMirrorEditor;

this._lastActiveEditor = mirrorEditor;

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