MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / collapseSelectionForRestore

Function collapseSelectionForRestore

src/lib/saveState.js:101–116  ·  view source on GitHub ↗
(selection)

Source from the content-addressed store, hash-verified

99};
100
101function collapseSelectionForRestore(selection) {
102 if (!selection?.ranges?.length) return selection;
103
104 const mainIndex =
105 selection.mainIndex >= 0 && selection.mainIndex < selection.ranges.length
106 ? selection.mainIndex
107 : 0;
108 const main = selection.ranges[mainIndex];
109 const head = Number.isFinite(main?.to) ? main.to : (main?.from ?? 0);
110 const cursor = Math.max(0, head | 0);
111
112 return {
113 ranges: [{ from: cursor, to: cursor }],
114 mainIndex: 0,
115 };
116}

Callers 1

saveState.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected