Skip to content

Commit

Permalink
allow using Ctrl-C to copy in vim mode
Browse files Browse the repository at this point in the history
Defaults to true for consistency with the jupyterlab-vim extension
  • Loading branch information
ianhi committed Oct 4, 2020
1 parent a59f89a commit ebab15c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/codemirror-extension/schema/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
"title": "Block Comment on MacOS keyboard",
"description": "Key command for block comment with MacOS",
"default": "Cmd-/"
},
"vim:CtrlC-to-copy": {
"type": "boolean",
"title": "Ctrl-C Copies in Vim mode",
"description": "If true disable the default vim action for Ctrl-C to allow copying using the keyboard.",
"default": true
}
},
"type": "object"
Expand Down
12 changes: 9 additions & 3 deletions packages/codemirror-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ function activateEditorCommands(

let toggleComment = 'Ctrl-/';
let toggleCommentMac = 'Cmd-/';
let vimDisableCtrlC = true;
let removeKeymaps: IDisposable[] = [];

/**
Expand Down Expand Up @@ -238,6 +239,9 @@ function activateEditorCommands(
toggleCommentMac =
(settings.get('toggleCommentMac').composite as string) ??
toggleCommentMac;
vimDisableCtrlC =
(settings.get('vim:CtrlC-to-copy').composite as boolean) ??
vimDisableCtrlC;
}

/**
Expand All @@ -253,6 +257,9 @@ function activateEditorCommands(
const extraKeys = editor.getOption('extraKeys') || {};
extraKeys[toggleComment] = 'toggleComment';
extraKeys[toggleCommentMac] = 'toggleComment';
if (vimDisableCtrlC && keyMap === 'vim') {
extraKeys['Ctrl-C'] = false;
}
editor.setOption('extraKeys', extraKeys);
}

Expand Down Expand Up @@ -307,8 +314,8 @@ function activateEditorCommands(
// connect to signal here to ensure vim keymap has
// been imported in case we need it
/**
* Handle settings of Notebook cells
*/
* Handle settings of Notebook cells
*/
notebookTracker.newCellCreated.connect((sender, cell) => {
if (cell?.inputArea.editor instanceof CodeMirrorEditor) {
setEditorOptions(cell.inputArea.editor);
Expand All @@ -321,7 +328,6 @@ function activateEditorCommands(
updateNotebookTracker();
});


/**
* A test for whether the tracker has an active widget.
*/
Expand Down

0 comments on commit ebab15c

Please sign in to comment.