MCPcopy
hub / github.com/Doorman11991/smallcode / visualCursorPosition

Function visualCursorPosition

src/tui/fullscreen.js:40–55  ·  view source on GitHub ↗
(str, cursorIdx, maxVisualWidth)

Source from the content-addressed store, hash-verified

38
39// Compute cursor visual (line, col) from character index into str.
40function visualCursorPosition(str, cursorIdx, maxVisualWidth) {
41 let line = 0;
42 let col = 0;
43 let charIdx = 0;
44 for (const ch of str) {
45 if (charIdx >= cursorIdx) break;
46 const w = visualWidth(ch);
47 if (col + w > maxVisualWidth) {
48 line++;
49 col = 0;
50 }
51 col += w;
52 charIdx++;
53 }
54 return { line, col };
55}
56
57// ─── ANSI Escape Sequences ───────────────────────────────────────────────────
58

Callers 1

renderMethod · 0.85

Calls 1

visualWidthFunction · 0.85

Tested by

no test coverage detected