(editor: vs.TextEditor, selections: readonly vs.Selection[], prefixes: string[])
| 187 | } |
| 188 | |
| 189 | private async removeLinePrefixes(editor: vs.TextEditor, selections: readonly vs.Selection[], prefixes: string[]) { |
| 190 | const document = editor.document; |
| 191 | // In case we have overlapping selections, keep track of lines we've done. |
| 192 | const doneLines = new Set<number>(); |
| 193 | |
| 194 | await editor.edit((edit) => { |
| 195 | for (const selection of selections) { |
| 196 | for (let lineNumber = selection.start.line; lineNumber <= selection.end.line; lineNumber++) { |
| 197 | if (doneLines.has(lineNumber)) |
| 198 | continue; |
| 199 | doneLines.add(lineNumber); |
| 200 | |
| 201 | const line = document.lineAt(lineNumber); |
| 202 | if (line.isEmptyOrWhitespace) |
| 203 | continue; |
| 204 | |
| 205 | const lineContentStart = line.range.start.translate(0, line.firstNonWhitespaceCharacterIndex); |
| 206 | for (const prefix of prefixes) { |
| 207 | const possiblePrefixRange = new vs.Range(lineContentStart, lineContentStart.translate(0, prefix.length)); |
| 208 | const possiblePrefix = document.getText(possiblePrefixRange); |
| 209 | if (possiblePrefix === prefix) { |
| 210 | edit.delete(possiblePrefixRange); |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | }); |
| 217 | } |
| 218 | |
| 219 | public dispose(): void { |
| 220 | disposeAll(this.disposables); |
no test coverage detected