MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / findVisualLineAt

Method findVisualLineAt

packages/pi-tui/src/components/editor.ts:1828–1845  ·  view source on GitHub ↗

* Find the visual line index that contains the given logical position.

(
		visualLines: Array<{ logicalLine: number; startCol: number; length: number }>,
		line: number,
		col: number,
	)

Source from the content-addressed store, hash-verified

1826 * Find the visual line index that contains the given logical position.
1827 */
1828 private findVisualLineAt(
1829 visualLines: Array<{ logicalLine: number; startCol: number; length: number }>,
1830 line: number,
1831 col: number,
1832 ): number {
1833 for (let i = 0; i < visualLines.length; i++) {
1834 const vl = visualLines[i];
1835 if (!vl || vl.logicalLine !== line) continue;
1836 const offset = col - vl.startCol;
1837 // Cursor is in this segment if it's within range. For the last
1838 // segment of a logical line, cursor can be at length (end position)
1839 const isLastSegmentOfLine = i === visualLines.length - 1 || visualLines[i + 1]?.logicalLine !== vl.logicalLine;
1840 if (offset >= 0 && (offset < vl.length || (isLastSegmentOfLine && offset === vl.length))) {
1841 return i;
1842 }
1843 }
1844 return visualLines.length - 1;
1845 }
1846
1847 /**
1848 * Find the visual line index for the current cursor position.

Callers 2

moveToVisualLineMethod · 0.95
findCurrentVisualLineMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected