MCPcopy Create free account
hub / github.com/bigcode-project/jupytercoder / buildValues

Function buildValues

src/diff.js:206–257  ·  view source on GitHub ↗
(diff, components, newString, oldString, useLongestToken)

Source from the content-addressed store, hash-verified

204 };
205
206 function buildValues(diff, components, newString, oldString, useLongestToken) {
207 var componentPos = 0,
208 componentLen = components.length,
209 newPos = 0,
210 oldPos = 0;
211
212 for (; componentPos < componentLen; componentPos++) {
213 var component = components[componentPos];
214
215 if (!component.removed) {
216 if (!component.added && useLongestToken) {
217 var value = newString.slice(newPos, newPos + component.count);
218 value = value.map(function (value, i) {
219 var oldValue = oldString[oldPos + i];
220 return oldValue.length > value.length ? oldValue : value;
221 });
222 component.value = diff.join(value);
223 } else {
224 component.value = diff.join(newString.slice(newPos, newPos + component.count));
225 }
226
227 newPos += component.count; // Common case
228
229 if (!component.added) {
230 oldPos += component.count;
231 }
232 } else {
233 component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
234 oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
235 // The diffing algorithm is tied to add then remove output and this is the simplest
236 // route to get the desired output with minimal overhead.
237
238 if (componentPos && components[componentPos - 1].added) {
239 var tmp = components[componentPos - 1];
240 components[componentPos - 1] = components[componentPos];
241 components[componentPos] = tmp;
242 }
243 }
244 } // Special case handle for when one terminal is ignored (i.e. whitespace).
245 // For this case we merge the terminal into the prior string and drop the change.
246 // This is only available for string mode.
247
248
249 var lastComponent = components[componentLen - 1];
250
251 if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
252 components[componentLen - 2].value += lastComponent.value;
253 components.pop();
254 }
255
256 return components;
257 }
258
259 function clonePath(path) {
260 return {

Callers 1

execEditLengthFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected