MCPcopy Index your code
hub / github.com/midrender/revideo / extractRange

Function extractRange

packages/2d/src/lib/code/extractRange.ts:18–126  ·  view source on GitHub ↗
(
  range: CodeRange,
  fragments: CodeTag[],
)

Source from the content-addressed store, hash-verified

16 * isolated fragment within.
17 */
18export function extractRange(
19 range: CodeRange,
20 fragments: CodeTag[],
21): [CodeTag[], number] {
22 const [from, to] = range;
23 let [fromRow, fromColumn] = from;
24 let [toRow, toColumn] = to;
25 if (fromRow > toRow || (fromRow === toRow && fromColumn > toColumn)) {
26 [fromRow, fromColumn] = to;
27 [toRow, toColumn] = from;
28 }
29
30 let currentRow = 0;
31 let currentColumn = 0;
32 const newFragments: CodeTag[] = [];
33 let index = -1;
34 let found = false;
35 let extracted = '';
36
37 for (const fragment of fragments) {
38 if (found) {
39 newFragments.push(fragment);
40 continue;
41 }
42
43 const resolved = resolveCodeTag(fragment, false);
44 const lines = resolved.split('\n');
45 const newRows = lines.length - 1;
46 const lastColumn = lines[newRows].length;
47 const nextColumn = newRows > 0 ? lastColumn : currentColumn + lastColumn;
48
49 if (
50 fromRow > currentRow + newRows ||
51 (fromRow === currentRow + newRows && fromColumn > nextColumn)
52 ) {
53 currentRow += newRows;
54 currentColumn = nextColumn;
55 newFragments.push(fragment);
56 continue;
57 }
58
59 for (let i = 0; i < resolved.length; i++) {
60 const char = resolved.charAt(i);
61 if (fromRow === currentRow && fromColumn >= currentColumn) {
62 if (fromColumn === currentColumn) {
63 index = newFragments.length + 1;
64 newFragments.push(resolved.slice(0, i), '');
65 } else if (char === '\n') {
66 index = newFragments.length + 1;
67 newFragments.push(
68 resolved.slice(0, i) + ' '.repeat(fromColumn - currentColumn),
69 '',
70 );
71 }
72 }
73
74 if (index !== -1 && toRow === currentRow && toColumn >= currentColumn) {
75 if (toColumn === currentColumn) {

Callers 2

replaceMethod · 0.90
replaceTweenMethod · 0.90

Calls 2

resolveCodeTagFunction · 0.90
splitMethod · 0.45

Tested by

no test coverage detected