(chunks: RMarkdownChunk[], line: number)
| 144 | } |
| 145 | |
| 146 | export function getCurrentChunk(chunks: RMarkdownChunk[], line: number): RMarkdownChunk | undefined { |
| 147 | const textEditor = vscode.window.activeTextEditor; |
| 148 | if (!textEditor) { |
| 149 | void vscode.window.showWarningMessage('No text editor active.'); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | // Case: If `chunks` is empty, return undefined |
| 154 | if (chunks.length === 0) { |
| 155 | return undefined; |
| 156 | } |
| 157 | |
| 158 | // Case: Cursor is above first chunk, use first chunk |
| 159 | if (line < chunks[0].startLine) { |
| 160 | return chunks[0]; |
| 161 | } |
| 162 | // Case: Cursor is below last chunk, return last chunk |
| 163 | if (line > chunks[chunks.length - 1].endLine) { |
| 164 | return chunks[chunks.length - 1]; |
| 165 | } |
| 166 | // chunks.filter(i => line >= i.startLine)[0]; |
| 167 | for (const chunk of chunks) { |
| 168 | // Case: Cursor is within chunk, use current chunk |
| 169 | // Case: Cursor is between, use next chunk below cursor |
| 170 | if (chunk.endLine >= line) { |
| 171 | return chunk; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | function getPreviousChunk(chunks: RMarkdownChunk[], line: number): RMarkdownChunk | undefined { |
| 177 | const currentChunk = getCurrentChunk(chunks, line); |
no outgoing calls
no test coverage detected