Function
visualCursorPosition
(str, cursorIdx, maxVisualWidth)
Source from the content-addressed store, hash-verified
| 38 | |
| 39 | // Compute cursor visual (line, col) from character index into str. |
| 40 | function 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 | |
Tested by
no test coverage detected