(str, maxVisualWidth)
| 17 | |
| 18 | // Split string into visual lines, each no wider than maxVisualWidth. |
| 19 | function visualWrap(str, maxVisualWidth) { |
| 20 | if (str.length === 0) return ['']; |
| 21 | const lines = []; |
| 22 | let current = ''; |
| 23 | let curWidth = 0; |
| 24 | for (const ch of str) { |
| 25 | const w = visualWidth(ch); |
| 26 | if (curWidth + w > maxVisualWidth) { |
| 27 | lines.push(current); |
| 28 | current = ch; |
| 29 | curWidth = w; |
| 30 | } else { |
| 31 | current += ch; |
| 32 | curWidth += w; |
| 33 | } |
| 34 | } |
| 35 | if (current.length > 0) lines.push(current); |
| 36 | return lines; |
| 37 | } |
| 38 | |
| 39 | // Compute cursor visual (line, col) from character index into str. |
| 40 | function visualCursorPosition(str, cursorIdx, maxVisualWidth) { |
no test coverage detected