MCPcopy
hub / github.com/VSCodeVim/Vim / handleKeyAsAnAction

Method handleKeyAsAnAction

src/mode/modeHandler.ts:609–730  ·  view source on GitHub ↗
(key: string)

Source from the content-addressed store, hash-verified

607 }
608
609 private async handleKeyAsAnAction(key: string): Promise<boolean> {
610 if (vscode.window.activeTextEditor !== this.vimState.editor) {
611 Logger.warn('Current window is not active');
612 return false;
613 }
614
615 // Catch any text change not triggered by us (example: tab completion).
616 const changeAdded = this.vimState.historyTracker.addChange();
617 if (changeAdded) {
618 this.vimState.historyTracker.finishCurrentStep();
619 }
620
621 const recordedState = this.vimState.recordedState;
622 recordedState.actionKeys.push(key);
623 void VSCodeContext.set('vim.command', recordedState.commandString);
624
625 const action = getRelevantAction(recordedState.actionKeys, this.vimState);
626 switch (action) {
627 case KeypressState.NoPossibleMatch:
628 if (this.vimState.currentMode === Mode.Insert) {
629 this.vimState.recordedState.actionKeys = [];
630 } else {
631 this.vimState.recordedState = new RecordedState();
632 }
633 // Since there is no possible action we are no longer waiting any action keys
634 this.vimState.recordedState.waitingForAnotherActionKey = false;
635 void VSCodeContext.set('vim.command', '');
636
637 return false;
638 case KeypressState.WaitingOnKeys:
639 this.vimState.recordedState.waitingForAnotherActionKey = true;
640
641 return false;
642 }
643
644 if (
645 !this.remapState.remapUsedACharacter &&
646 this.remapState.isCurrentlyPerformingRecursiveRemapping
647 ) {
648 // Used a character inside a recursive remapping so we reset the mapDepth.
649 this.remapState.remapUsedACharacter = true;
650 this.remapState.mapDepth = 0;
651 }
652
653 // Since we got an action we are no longer waiting any action keys
654 this.vimState.recordedState.waitingForAnotherActionKey = false;
655
656 // Store action pressed keys for showCmd
657 recordedState.actionsRunPressedKeys.push(...recordedState.actionKeys);
658
659 let actionToRecord: BaseAction | undefined = action;
660 const lastAction = recordedState.actionsRun.at(-1);
661 if (lastAction === undefined) {
662 recordedState.actionsRun.push(action);
663 } else {
664 const actionCanBeMergedWithDocumentChange =
665 action instanceof TypeInInsertMode ||
666 action instanceof BackspaceInInsertMode ||

Callers 1

Calls 10

runActionMethod · 0.95
updateViewMethod · 0.95
getRelevantActionFunction · 0.90
warnMethod · 0.80
addChangeMethod · 0.80
finishCurrentStepMethod · 0.80
addChangesMethod · 0.80
recordJumpMethod · 0.80
fromStateBeforeMethod · 0.80
fromStateNowMethod · 0.80

Tested by

no test coverage detected