Skip to content

Commit 8bbdd4a

Browse files
committed
implement gcc
1 parent 71919db commit 8bbdd4a

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/cm_adapter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { RegExpCursor, setSearchQuery, SearchQuery } from "@codemirror/search"
55
import {
66
insertNewlineAndIndent, indentMore, indentLess, indentSelection, cursorCharLeft,
77
undo, redo, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorCharBackward,
8+
toggleLineComment
89
} from "@codemirror/commands"
910
import {vimState, CM5RangeInterface} from "./types"
1011

@@ -135,6 +136,7 @@ export class CodeMirror {
135136
static Pos = Pos;
136137
static StringStream = StringStream as unknown as StringStream & { new(_: string): StringStream }
137138
static commands = {
139+
toggleLineComment: function (cm: CodeMirror) { toggleLineComment(cm.cm6) },
138140
cursorCharLeft: function (cm: CodeMirror) { cursorCharLeft(cm.cm6); },
139141
redo: function (cm: CodeMirror) { runHistoryCommand(cm, false); },
140142
undo: function (cm: CodeMirror) { runHistoryCommand(cm, true); },
@@ -427,7 +429,7 @@ export class CodeMirror {
427429
};
428430

429431
execCommand(name: string) {
430-
if (name == "indentAuto") CodeMirror.commands.indentAuto(this);
432+
if (CodeMirror.commands.hasOwnProperty(name)) CodeMirror.commands[name](this);
431433
else if (name == "goLineLeft") cursorLineBoundaryBackward(this.cm6);
432434
else if (name == "goLineRight") {
433435
cursorLineBoundaryForward(this.cm6);

src/vim.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export function initVim(CM) {
175175
{ keys: 'g~', type: 'operator', operator: 'changeCase' },
176176
{ keys: 'gu', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: true}, isEdit: true },
177177
{ keys: 'gU', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: false}, isEdit: true },
178+
{ keys: 'gc', type: 'operator', operator: 'toggleComment', isEdit: true },
178179
{ keys: 'n', type: 'motion', motion: 'findNext', motionArgs: { forward: true, toJumplist: true }},
179180
{ keys: 'N', type: 'motion', motion: 'findNext', motionArgs: { forward: false, toJumplist: true }},
180181
{ keys: 'gn', type: 'motion', motion: 'findAndSelectNextInclusive', motionArgs: { forward: true }},
@@ -2861,6 +2862,10 @@ export function initVim(CM) {
28612862
if (endRow > from && operatorArgs.linewise) endRow--;
28622863
return operatorArgs.keepCursor ? oldAnchor : new Pos(endRow, 0);
28632864
},
2865+
toggleComment: function(cm, _args, ranges, oldAnchor, newHead) {
2866+
cm.execCommand("toggleLineComment");
2867+
return newHead;
2868+
},
28642869
changeCase: function(cm, args, ranges, oldAnchor, newHead) {
28652870
var selections = cm.getSelections();
28662871
var swapped = [];

0 commit comments

Comments
 (0)