MCPcopy Create free account
hub / github.com/cursorless-dev/cursorless / getEdits

Method getEdits

src/actions/BringMoveSwap.ts:93–177  ·  view source on GitHub ↗
(
    sources: TypedSelection[],
    destinations: TypedSelection[]
  )

Source from the content-addressed store, hash-verified

91 }
92
93 private getEdits(
94 sources: TypedSelection[],
95 destinations: TypedSelection[]
96 ): ExtendedEdit[] {
97 const usedSources: TypedSelection[] = [];
98 const results: ExtendedEdit[] = [];
99 const zipSources =
100 sources.length !== destinations.length &&
101 destinations.length === 1 &&
102 this.type !== "swap";
103
104 sources.forEach((source, i) => {
105 let destination = destinations[i];
106 if ((source == null || destination == null) && !zipSources) {
107 throw new Error("Targets must have same number of args");
108 }
109
110 if (destination != null) {
111 let text: string;
112 if (zipSources) {
113 text = sources
114 .map((source, i) => {
115 let text = source.selection.editor.document.getText(
116 source.selection.selection
117 );
118 const selectionContext = destination.selectionContext
119 .isRawSelection
120 ? source.selectionContext
121 : destination.selectionContext;
122 return i > 0 && selectionContext.containingListDelimiter
123 ? selectionContext.containingListDelimiter + text
124 : text;
125 })
126 .join("");
127 text = maybeAddDelimiter(text, destination);
128 } else {
129 // Get text adjusting for destination position
130 text = getTextWithPossibleDelimiter(source, destination);
131 }
132 // Add destination edit
133 results.push({
134 range: destination.selection.selection as Range,
135 text,
136 editor: destination.selection.editor,
137 originalSelection: destination,
138 isSource: false,
139 isReplace: destination.position === "after",
140 });
141 } else {
142 destination = destinations[0];
143 }
144
145 // Add source edit
146 // Prevent multiple instances of the same expanded source.
147 if (!usedSources.includes(source)) {
148 usedSources.push(source);
149 let text: string;
150 let range: Range;

Callers 1

runMethod · 0.95

Calls 3

maybeAddDelimiterFunction · 0.90
performOutsideAdjustmentFunction · 0.90

Tested by

no test coverage detected