MCPcopy Index your code
hub / github.com/continuedev/continue / getOffsetPositionAtLastNewLine

Function getOffsetPositionAtLastNewLine

core/nextEdit/diff/diff.ts:12–61  ·  view source on GitHub ↗
(
  diffLines: DiffLine[],
  lineContentAtCursorPos: string,
  lineOffsetAtCursorPos: number,
)

Source from the content-addressed store, hash-verified

10 * @returns Offset position at last new line inside the editable region.
11 */
12export function getOffsetPositionAtLastNewLine(
13 diffLines: DiffLine[],
14 lineContentAtCursorPos: string,
15 lineOffsetAtCursorPos: number,
16): {
17 line: number;
18 character: number;
19} {
20 let lastNewLineContent = "";
21 let lineOffset = -1;
22 let currentResultLine = 0;
23 let hasChanges = false;
24
25 // Build the string while tracking line numbers in the result
26 diffLines.reduce((acc, curr, i) => {
27 // Add the current line to our result
28 acc += curr.line;
29
30 // Add newline if not the last line
31 if (i < diffLines.length - 1) {
32 acc += "\n";
33 }
34
35 // If this is a "new" or "same" line, it will be part of the result
36 if (curr.type === "new" || curr.type === "same") {
37 if (curr.type === "new") {
38 // If it's a new line, update our tracking
39 lastNewLineContent = curr.line;
40 lineOffset = currentResultLine;
41 hasChanges = true;
42 }
43 // Increment our position in the result
44 currentResultLine++;
45 }
46
47 return acc;
48 }, "");
49
50 // If nothing has changed, return the original position
51 if (!hasChanges) {
52 lineOffset = lineOffsetAtCursorPos;
53 lastNewLineContent = lineContentAtCursorPos;
54 }
55 // Calculate the character position for the end of the last relevant line
56 const endOfCharPos = lastNewLineContent.length;
57 return {
58 line: lineOffset,
59 character: endOfCharPos,
60 };
61}
62
63export function getRenderableDiffWithGutterAnnotations(
64 diffLines: DiffLine[],

Callers 2

showNextEditWindowMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected