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

Class ModeHandler

src/mode/modeHandler.ts:71–1678  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69 * See: https://github.com/VSCodeVim/Vim/blob/master/.github/CONTRIBUTING.md#the-vim-state-machine
70 */
71export class ModeHandler implements vscode.Disposable, IModeHandler {
72 public readonly vimState: VimState;
73 public readonly remapState: RemapState;
74
75 public lastMovementFailed: boolean = false;
76
77 public focusChanged = false;
78
79 private searchDecorationCacheKey: { searchString: string; documentVersion: number } | undefined;
80
81 private readonly disposables: vscode.Disposable[] = [];
82 private readonly handlerMap: IModeHandlerMap;
83 private readonly remappers: Remappers;
84
85 public internalSelectionsTracker = new InternalSelectionsTracker();
86
87 /**
88 * Was the previous mouse click past EOL
89 */
90 private lastClickWasPastEol: boolean = false;
91
92 private _currentMode!: Mode;
93 private get currentMode(): Mode {
94 return this._currentMode;
95 }
96 private async setCurrentMode(mode: Mode): Promise<void> {
97 if (this.vimState.currentMode !== mode) {
98 await this.vimState.setCurrentMode(mode);
99 }
100 this._currentMode = mode;
101 }
102
103 public static async create(
104 handlerMap: IModeHandlerMap,
105 textEditor: vscode.TextEditor,
106 ): Promise<ModeHandler> {
107 const modeHandler = new ModeHandler(handlerMap, textEditor);
108 await modeHandler.vimState.load();
109 await modeHandler.setCurrentMode(configuration.startInInsertMode ? Mode.Insert : Mode.Normal);
110 modeHandler.syncCursors();
111 return modeHandler;
112 }
113
114 private constructor(handlerMap: IModeHandlerMap, textEditor: vscode.TextEditor) {
115 this.handlerMap = handlerMap;
116 this.remappers = new Remappers();
117
118 this.vimState = new VimState(textEditor, new EasyMotion());
119 this.remapState = new RemapState();
120 this.disposables.push(this.vimState);
121 }
122
123 /**
124 * Updates VSCodeVim's internal representation of cursors to match VSCode's selections.
125 * This loses some information, so it should only be done when necessary.
126 */
127 public syncCursors() {
128 // TODO: getCursorsAfterSync() is basically this, but stupider

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected