MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / getSelectedText

Function getSelectedText

packages/core/src/widgets/codeEditor.ts:450–474  ·  view source on GitHub ↗
(lines: readonly string[], selection: EditorSelection)

Source from the content-addressed store, hash-verified

448 * @returns Selected text
449 */
450export function getSelectedText(lines: readonly string[], selection: EditorSelection): string {
451 const [start, end] = normalizeSelection(selection);
452
453 if (start.line === end.line) {
454 const line = lines[start.line] ?? "";
455 return line.slice(start.column, end.column);
456 }
457
458 const result: string[] = [];
459
460 // First line
461 const firstLine = lines[start.line] ?? "";
462 result.push(firstLine.slice(start.column));
463
464 // Middle lines
465 for (let i = start.line + 1; i < end.line; i++) {
466 result.push(lines[i] ?? "");
467 }
468
469 // Last line
470 const lastLine = lines[end.line] ?? "";
471 result.push(lastLine.slice(0, end.column));
472
473 return result.join("\n");
474}
475
476/**
477 * Compute scroll position to ensure cursor is visible.

Callers 3

routeEngineEventImplFunction · 0.85

Calls 2

normalizeSelectionFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected