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

Function doExecuteNormal

src/transformations/execute.ts:306–348  ·  view source on GitHub ↗
(
  modeHandler: IModeHandler,
  transformation: ExecuteNormalTransformation,
)

Source from the content-addressed store, hash-verified

304}
305
306const doExecuteNormal = async (
307 modeHandler: IModeHandler,
308 transformation: ExecuteNormalTransformation,
309) => {
310 const vimState = modeHandler.vimState;
311 const { keystrokes, range } = transformation;
312 const strokes = keystrokesExpressionParser.parse(keystrokes);
313 if (!strokes.status) {
314 throw new Error(`Failed to execute normal command: ${keystrokes}`);
315 }
316
317 const resultLineNumbers: number[] = [];
318 if (range) {
319 const { start: startLineNumber, end: endLineNumber } = range.resolve(vimState);
320 for (let i = startLineNumber; i <= endLineNumber; i++) {
321 resultLineNumbers.push(i);
322 }
323 } else {
324 const selectionList = vimState.editor.selections;
325 for (const selection of selectionList) {
326 const { start, end } = selection;
327
328 for (let i = start.line; i <= end.line; i++) {
329 resultLineNumbers.push(i);
330 }
331 }
332 }
333
334 vimState.normalCommandState = NormalCommandState.Executing;
335 vimState.recordedState = new RecordedState();
336 await vimState.setCurrentMode(Mode.Normal);
337 for (const lineNumber of resultLineNumbers) {
338 if (range) {
339 vimState.cursorStopPosition = vimState.cursorStartPosition =
340 TextEditor.getFirstNonWhitespaceCharOnLine(vimState.document, lineNumber);
341 }
342 await modeHandler.handleMultipleKeyEvents(strokes.value);
343 if (vimState.currentMode === Mode.Insert) {
344 await modeHandler.handleKeyEvent('<Esc>');
345 }
346 }
347 vimState.normalCommandState = NormalCommandState.Finished;
348};

Callers 1

executeTransformationsFunction · 0.85

Calls 6

resolveMethod · 0.65
handleKeyEventMethod · 0.65
parseMethod · 0.45
setCurrentModeMethod · 0.45

Tested by

no test coverage detected