()
| 1080 | } |
| 1081 | |
| 1082 | private async executeOperator(): Promise<void> { |
| 1083 | const recordedState = this.vimState.recordedState; |
| 1084 | const operator = recordedState.operator!; |
| 1085 | |
| 1086 | // TODO - if actions were more pure, this would be unnecessary. |
| 1087 | const startingMode = this.vimState.currentMode; |
| 1088 | const startingRegisterMode = this.vimState.currentRegisterMode; |
| 1089 | |
| 1090 | const resultingCursors: Cursor[] = []; |
| 1091 | for (let [i, { start, stop }] of this.vimState.cursors.entries()) { |
| 1092 | operator.multicursorIndex = i; |
| 1093 | |
| 1094 | if (start.isAfter(stop)) { |
| 1095 | [start, stop] = [stop, start]; |
| 1096 | } |
| 1097 | |
| 1098 | if (!isVisualMode(startingMode) && startingRegisterMode !== RegisterMode.LineWise) { |
| 1099 | stop = stop.getLeftThroughLineBreaks(true); |
| 1100 | } |
| 1101 | |
| 1102 | if (this.currentMode === Mode.VisualLine) { |
| 1103 | start = start.getLineBegin(); |
| 1104 | stop = stop.getLineEnd(); |
| 1105 | |
| 1106 | this.vimState.currentRegisterMode = RegisterMode.LineWise; |
| 1107 | } |
| 1108 | |
| 1109 | await this.vimState.setCurrentMode(startingMode); |
| 1110 | |
| 1111 | // We run the repeat version of an operator if the last 2 operators are the same. |
| 1112 | const operators = recordedState.operators; |
| 1113 | if (operators.length > 1 && operators[0].constructor === operators[1].constructor) { |
| 1114 | await operator.runRepeat(this.vimState, start, recordedState.count); |
| 1115 | } else { |
| 1116 | await operator.run(this.vimState, start, stop); |
| 1117 | } |
| 1118 | |
| 1119 | for (const transformation of this.vimState.recordedState.transformer.transformations) { |
| 1120 | if (isTextTransformation(transformation) && transformation.cursorIndex === undefined) { |
| 1121 | transformation.cursorIndex = operator.multicursorIndex; |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | const resultingCursor = new Cursor( |
| 1126 | this.vimState.cursorStartPosition, |
| 1127 | this.vimState.cursorStopPosition, |
| 1128 | ); |
| 1129 | |
| 1130 | resultingCursors.push(resultingCursor); |
| 1131 | } |
| 1132 | |
| 1133 | if (this.vimState.recordedState.transformer.transformations.length > 0) { |
| 1134 | const transformer = this.vimState.recordedState.transformer; |
| 1135 | await executeTransformations(this, transformer.transformations); |
| 1136 | } else { |
| 1137 | // Keep track of all cursors (in the case of multi-cursor). |
| 1138 | this.vimState.cursors = resultingCursors; |
| 1139 | } |
no test coverage detected