Skip to content
Closed
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@codemirror/language": "^6.1.0",
"@codemirror/search": "^6.2.0",
"@codemirror/state": "^6.0.1",
"@codemirror/view": "^6.0.3"
"@codemirror/view": "^6.3.0"
},
"devDependencies": {
"codemirror": "6.0.0",
Expand Down
92 changes: 50 additions & 42 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EditorView,
showPanel,
Panel,
keymap,
} from "@codemirror/view";
import { setSearchQuery } from "@codemirror/search";

Expand Down Expand Up @@ -182,54 +183,61 @@ const vimPlugin = ViewPlugin.fromClass(
decorations = Decoration.none;
},
{
eventHandlers: {
keydown: function (e: KeyboardEvent, view: EditorView) {
const key = CodeMirror.vimKey(e);
const cm = this.cm;
if (!key) return;
decorations: (v) => v.decorations,

// clear search highlight
let vim = cm.state.vim;
if (
key == "<Esc>" &&
!vim.insertMode &&
!vim.visualMode &&
this.query /* && !cm.inMultiSelectMode*/
) {
const searchState = vim.searchState_
if (searchState) {
cm.removeOverlay(searchState.getOverlay())
searchState.setOverlay(null);
}
}
provide: plugin => {
return keymap.of([
{
any: function(view, e) {
const pluginInstance = view.plugin(plugin)
if (!pluginInstance) return false;

cm.state.vim.status = (cm.state.vim.status || "") + key;
let result = Vim.multiSelectHandleKey(cm, key, "user");
const key = CodeMirror.vimKey(e);
const cm = pluginInstance.cm;
if (!key) return false;

// insert mode
if (!result && cm.state.vim.insertMode && cm.state.overwrite) {
if (e.key && e.key.length == 1 && !/\n/.test(e.key)) {
result = true;
cm.overWriteSelection(e.key);
} else if (e.key == "Backspace") {
result = true;
CodeMirror.commands.cursorCharLeft(cm);
}
}
if (result) {
CodeMirror.signal(this.cm, 'vim-keypress', key);
e.preventDefault();
e.stopPropagation();
this.blockCursor.scheduleRedraw();
}
// clear search highlight
let vim = cm.state.vim;
if (
key == "<Esc>" &&
!vim.insertMode &&
!vim.visualMode &&
pluginInstance.query /* && !cm.inMultiSelectMode*/
) {
const searchState = vim.searchState_
if (searchState) {
cm.removeOverlay(searchState.getOverlay())
searchState.setOverlay(null);
}
}

this.updateStatus();
cm.state.vim.status = (cm.state.vim.status || "") + key;
let result = Vim.multiSelectHandleKey(cm, key, "user");

return !!result;
},
},
// insert mode
if (!result && cm.state.vim.insertMode && cm.state.overwrite) {
if (e.key && e.key.length == 1 && !/\n/.test(e.key)) {
result = true;
cm.overWriteSelection(e.key);
} else if (e.key == "Backspace") {
result = true;
CodeMirror.commands.cursorCharLeft(cm);
}
}
if (result) {
CodeMirror.signal(cm, 'vim-keypress', key);
e.preventDefault();
e.stopPropagation();
pluginInstance.blockCursor.scheduleRedraw();
}

decorations: (v) => v.decorations,
pluginInstance.updateStatus();

return !!result;
}
}
])
}
}
);

Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1055,9 +1055,9 @@ safe-buffer@~5.1.0, safe-buffer@~5.1.1:
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==

selenium-webdriver@^4.0.0-beta.3:
version "4.4.0"
resolved "https://registry.yarnpkg.com/selenium-webdriver/-/selenium-webdriver-4.4.0.tgz#3f280504f6c0ac64a24b176304213b5a49ec2553"
integrity sha512-Du+/xfpvNi9zHAeYgXhOWN9yH0hph+cuX+hHDBr7d+SbtQVcfNJwBzLsbdHrB1Wh7MHXFuIkSG88A9TRRQUx3g==
version "4.5.0"
resolved "https://registry.yarnpkg.com/selenium-webdriver/-/selenium-webdriver-4.5.0.tgz#7e20d0fc038177970dad81159950c12f7411ac0d"
integrity sha512-9mSFii+lRwcnT2KUAB1kqvx6+mMiiQHH60Y0VUtr3kxxi3oZ3CV3B8e2nuJ7T4SPb+Q6VA0swswe7rYpez07Bg==
dependencies:
jszip "^3.10.0"
tmp "^0.2.1"
Expand Down