MCPcopy Index your code
hub / github.com/CodeGraphContext/CodeGraphContext /

Class

website/public/wasm/web-tree-sitter.js:5–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4// src/edit.ts
5var Edit = class {
6 static {
7 __name(this, "Edit");
8 }
9 /** The start position of the change. */
10 startPosition;
11 /** The end position of the change before the edit. */
12 oldEndPosition;
13 /** The end position of the change after the edit. */
14 newEndPosition;
15 /** The start index of the change. */
16 startIndex;
17 /** The end index of the change before the edit. */
18 oldEndIndex;
19 /** The end index of the change after the edit. */
20 newEndIndex;
21 constructor({
22 startIndex,
23 oldEndIndex,
24 newEndIndex,
25 startPosition,
26 oldEndPosition,
27 newEndPosition
28 }) {
29 this.startIndex = startIndex >>> 0;
30 this.oldEndIndex = oldEndIndex >>> 0;
31 this.newEndIndex = newEndIndex >>> 0;
32 this.startPosition = startPosition;
33 this.oldEndPosition = oldEndPosition;
34 this.newEndPosition = newEndPosition;
35 }
36 /**
37 * Edit a point and index to keep it in-sync with source code that has been edited.
38 *
39 * This function updates a single point's byte offset and row/column position
40 * based on an edit operation. This is useful for editing points without
41 * requiring a tree or node instance.
42 */
43 editPoint(point, index) {
44 let newIndex = index;
45 const newPoint = { ...point };
46 if (index >= this.oldEndIndex) {
47 newIndex = this.newEndIndex + (index - this.oldEndIndex);
48 const originalRow = point.row;
49 newPoint.row = this.newEndPosition.row + (point.row - this.oldEndPosition.row);
50 newPoint.column = originalRow === this.oldEndPosition.row ? this.newEndPosition.column + (point.column - this.oldEndPosition.column) : point.column;
51 } else if (index > this.startIndex) {
52 newIndex = this.newEndIndex;
53 newPoint.row = this.newEndPosition.row;
54 newPoint.column = this.newEndPosition.column;
55 }
56 return { point: newPoint, index: newIndex };
57 }
58 /**
59 * Edit a range to keep it in-sync with source code that has been edited.
60 *
61 * This function updates a range's start and end positions based on an edit
62 * operation. This is useful for editing ranges without requiring a tree

Callers

nothing calls this directly

Calls 1

__nameFunction · 0.85

Tested by

no test coverage detected