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

Function visualWrap

src/tui/fullscreen.js:19–37  ·  view source on GitHub ↗
(str, maxVisualWidth)

Source from the content-addressed store, hash-verified

17
18// Split string into visual lines, each no wider than maxVisualWidth.
19function 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.
40function visualCursorPosition(str, cursorIdx, maxVisualWidth) {

Callers 1

_renderInputMethod · 0.85

Calls 1

visualWidthFunction · 0.85

Tested by

no test coverage detected