(selection)
| 99 | }; |
| 100 | |
| 101 | function 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 | } |