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

Function executeTransformations

src/transformations/execute.ts:41–304  ·  view source on GitHub ↗
(
  modeHandler: IModeHandler,
  transformations: Transformation[],
)

Source from the content-addressed store, hash-verified

39}
40
41export async function executeTransformations(
42 modeHandler: IModeHandler,
43 transformations: Transformation[],
44) {
45 if (transformations.length === 0) {
46 return;
47 }
48
49 const vimState = modeHandler.vimState;
50
51 const textTransformations = transformations.filter((x): x is TextTransformations =>
52 isTextTransformation(x),
53 );
54 const multicursorTextTransformations: InsertTextVSCodeTransformation[] = transformations.filter(
55 (x): x is InsertTextVSCodeTransformation => isMultiCursorTextTransformation(x),
56 );
57
58 const otherTransformations = transformations.filter(
59 (x) => !isTextTransformation(x) && !isMultiCursorTextTransformation(x),
60 );
61
62 const accumulatedPositionDifferences: { [key: number]: PositionDiff[] } = {};
63
64 const doTextEditorEdit = (command: TextTransformations, edit: vscode.TextEditorEdit) => {
65 switch (command.type) {
66 case 'insertText':
67 edit.insert(command.position, command.text);
68 break;
69 case 'replaceText':
70 edit.replace(command.range, command.text);
71 break;
72 case 'deleteRange':
73 edit.delete(command.range);
74 break;
75 case 'moveCursor':
76 break;
77 default:
78 Logger.warn(`Unhandled text transformation type: ${command.type}.`);
79 break;
80 }
81
82 if (command.diff) {
83 if (command.cursorIndex === undefined) {
84 throw new Error('No cursor index - this should never ever happen!');
85 }
86
87 if (!accumulatedPositionDifferences[command.cursorIndex]) {
88 accumulatedPositionDifferences[command.cursorIndex] = [];
89 }
90
91 accumulatedPositionDifferences[command.cursorIndex].push(command.diff);
92 }
93 };
94
95 if (textTransformations.length > 0) {
96 const overlapping = overlappingTransformations(textTransformations);
97 if (overlapping !== undefined) {
98 const msg = `Transformations overlapping: ${JSON.stringify(overlapping)}`;

Callers 2

runActionMethod · 0.90
executeOperatorMethod · 0.90

Calls 15

isTextTransformationFunction · 0.90
areAllSameTransformationFunction · 0.90
doTextEditorEditFunction · 0.85
doExecuteNormalFunction · 0.85
warnMethod · 0.80
editMethod · 0.80
FromVSCodeSelectionMethod · 0.80
withNewStopMethod · 0.80
rerunRecordedStateMethod · 0.65

Tested by

no test coverage detected