MCPcopy Create free account
hub / github.com/anus-dev/ANUS / logicalPosToOffset

Function logicalPosToOffset

packages/cli/src/ui/components/shared/text-buffer.ts:651–672  ·  view source on GitHub ↗
(
  lines: string[],
  row: number,
  col: number,
)

Source from the content-addressed store, hash-verified

649 * Inverse operation of offsetToLogicalPos
650 */
651export function logicalPosToOffset(
652 lines: string[],
653 row: number,
654 col: number,
655): number {
656 let offset = 0;
657
658 // Clamp row to valid range
659 const actualRow = Math.min(row, lines.length - 1);
660
661 // Add lengths of all lines before the target row
662 for (let i = 0; i < actualRow; i++) {
663 offset += cpLen(lines[i]) + 1; // +1 for newline
664 }
665
666 // Add column offset within the target row
667 if (actualRow >= 0 && actualRow < lines.length) {
668 offset += Math.min(col, cpLen(lines[actualRow]));
669 }
670
671 return offset;
672}
673
674// Helper to calculate visual lines and map cursor positions
675function calculateVisualLayout(

Callers 3

InputPromptFunction · 0.85
useCommandCompletionFunction · 0.85

Calls 1

cpLenFunction · 0.85

Tested by

no test coverage detected