( state: EditorState, saved: FoldSpan[], )
| 129 | } |
| 130 | |
| 131 | function loadFolds( |
| 132 | state: EditorState, |
| 133 | saved: FoldSpan[], |
| 134 | ): StateEffect<{ from: number; to: number }>[] { |
| 135 | const doc = state.doc; |
| 136 | const effects: StateEffect<{ from: number; to: number }>[] = []; |
| 137 | |
| 138 | for (const f of saved) { |
| 139 | // Validate line numbers |
| 140 | if (f.fromLine < 1 || f.fromLine > doc.lines) continue; |
| 141 | if (f.toLine < 1 || f.toLine > doc.lines) continue; |
| 142 | |
| 143 | const from = lineColToOffset(doc, f.fromLine, f.fromCol); |
| 144 | const to = lineColToOffset(doc, f.toLine, f.toCol); |
| 145 | if (to > from) { |
| 146 | effects.push(foldEffect.of({ from, to })); |
| 147 | } |
| 148 | } |
| 149 | return effects; |
| 150 | } |
| 151 | |
| 152 | const restoreEffects = loadFolds(view.state, folds); |
| 153 | if (restoreEffects.length) { |
no test coverage detected