Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/cm_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RegExpCursor, setSearchQuery, SearchQuery } from "@codemirror/search"
import {
insertNewlineAndIndent, indentMore, indentLess, indentSelection, cursorCharLeft,
undo, redo, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorCharBackward,
toggleLineComment
} from "@codemirror/commands"
import {vimState, CM5RangeInterface} from "./types"

Expand Down Expand Up @@ -135,6 +136,7 @@ export class CodeMirror {
static Pos = Pos;
static StringStream = StringStream as unknown as StringStream & { new(_: string): StringStream }
static commands = {
toggleLineComment: function (cm: CodeMirror) { toggleLineComment(cm.cm6) },
cursorCharLeft: function (cm: CodeMirror) { cursorCharLeft(cm.cm6); },
redo: function (cm: CodeMirror) { runHistoryCommand(cm, false); },
undo: function (cm: CodeMirror) { runHistoryCommand(cm, true); },
Expand Down Expand Up @@ -427,7 +429,7 @@ export class CodeMirror {
};

execCommand(name: string) {
if (name == "indentAuto") CodeMirror.commands.indentAuto(this);
if (CodeMirror.commands.hasOwnProperty(name)) CodeMirror.commands[name](this);
else if (name == "goLineLeft") cursorLineBoundaryBackward(this.cm6);
else if (name == "goLineRight") {
cursorLineBoundaryForward(this.cm6);
Expand Down
5 changes: 5 additions & 0 deletions src/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export function initVim(CM) {
{ keys: 'g~', type: 'operator', operator: 'changeCase' },
{ keys: 'gu', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: true}, isEdit: true },
{ keys: 'gU', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: false}, isEdit: true },
{ keys: 'gc', type: 'operator', operator: 'toggleComment', isEdit: true },
{ keys: 'n', type: 'motion', motion: 'findNext', motionArgs: { forward: true, toJumplist: true }},
{ keys: 'N', type: 'motion', motion: 'findNext', motionArgs: { forward: false, toJumplist: true }},
{ keys: 'gn', type: 'motion', motion: 'findAndSelectNextInclusive', motionArgs: { forward: true }},
Expand Down Expand Up @@ -2861,6 +2862,10 @@ export function initVim(CM) {
if (endRow > from && operatorArgs.linewise) endRow--;
return operatorArgs.keepCursor ? oldAnchor : new Pos(endRow, 0);
},
toggleComment: function(cm, _args, ranges, oldAnchor, newHead) {
cm.execCommand("toggleLineComment");
return newHead;
},
changeCase: function(cm, args, ranges, oldAnchor, newHead) {
var selections = cm.getSelections();
var swapped = [];
Expand Down