MCPcopy Index your code
hub / github.com/VSCodeVim/Vim / executeMovement

Method executeMovement

src/mode/modeHandler.ts:989–1080  ·  view source on GitHub ↗
(movement: BaseMovement)

Source from the content-addressed store, hash-verified

987 }
988
989 private async executeMovement(movement: BaseMovement): Promise<RecordedState> {
990 this.lastMovementFailed = false;
991 const recordedState = this.vimState.recordedState;
992 const cursorsToRemove: number[] = [];
993
994 for (let i = 0; i < this.vimState.cursors.length; i++) {
995 /**
996 * Essentially what we're doing here is pretending like the
997 * current VimState only has one cursor (the cursor that we just
998 * iterated to).
999 *
1000 * We set the cursor position to be equal to the iterated one,
1001 * and then set it back immediately after we're done.
1002 *
1003 * The slightly more complicated logic here allows us to write
1004 * Action definitions without having to think about multiple
1005 * cursors in almost all cases.
1006 */
1007 const oldCursorPositionStart = this.vimState.cursorStartPosition;
1008 const oldCursorPositionStop = this.vimState.cursorStopPosition;
1009 movement.multicursorIndex = i;
1010
1011 this.vimState.cursorStartPosition = this.vimState.cursors[i].start;
1012 const cursorPosition = this.vimState.cursors[i].stop;
1013 this.vimState.cursorStopPosition = cursorPosition;
1014
1015 const result = await movement.execActionWithCount(
1016 cursorPosition,
1017 this.vimState,
1018 recordedState.count,
1019 );
1020
1021 // We also need to update the specific cursor, in case the cursor position was modified inside
1022 // the handling functions (e.g. 'it')
1023 this.vimState.cursors[i] = new Cursor(
1024 this.vimState.cursorStartPosition,
1025 this.vimState.cursorStopPosition,
1026 );
1027
1028 this.vimState.cursorStartPosition = oldCursorPositionStart;
1029 this.vimState.cursorStopPosition = oldCursorPositionStop;
1030
1031 if (result instanceof Position) {
1032 this.vimState.cursors[i] = this.vimState.cursors[i].withNewStop(result);
1033
1034 if (!isVisualMode(this.currentMode) && !this.vimState.recordedState.operator) {
1035 this.vimState.cursors[i] = this.vimState.cursors[i].withNewStart(result);
1036 }
1037 } else {
1038 if (result.failed) {
1039 this.vimState.recordedState = new RecordedState();
1040 this.lastMovementFailed = true;
1041 }
1042
1043 if (result.removed) {
1044 cursorsToRemove.push(i);
1045 } else {
1046 this.vimState.cursors[i] = new Cursor(result.start, result.stop);

Callers 1

runActionMethod · 0.95

Calls 6

isVisualModeFunction · 0.90
withNewStopMethod · 0.80
withNewStartMethod · 0.80
getLineLengthMethod · 0.80
getLineEndMethod · 0.80
execActionWithCountMethod · 0.65

Tested by

no test coverage detected