()
| 45 | } |
| 46 | |
| 47 | export function getSelection(): RSelection | undefined { |
| 48 | const textEditor = window.activeTextEditor; |
| 49 | if (!textEditor) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | const currentDocument = textEditor.document; |
| 54 | const { start, end } = textEditor.selection; |
| 55 | const selection = { |
| 56 | linesDownToMoveCursor: 0, |
| 57 | selectedText: '', |
| 58 | startLine: start.line, |
| 59 | endLine: end.line, |
| 60 | range: new Range(start, end) |
| 61 | }; |
| 62 | |
| 63 | if (selection.range.isEmpty) { |
| 64 | const {startLine, endLine} = extendSelection( |
| 65 | start.line, |
| 66 | (x) => currentDocument.lineAt(x).text, |
| 67 | currentDocument.lineCount |
| 68 | ); |
| 69 | const charactersOnLine = textEditor.document.lineAt(endLine).text.length; |
| 70 | const newStart = new Position(startLine, 0); |
| 71 | const newEnd = new Position(endLine, charactersOnLine); |
| 72 | selection.linesDownToMoveCursor = endLine + 1 - start.line; |
| 73 | selection.range = new Range(newStart, newEnd); |
| 74 | } |
| 75 | |
| 76 | let selectedText = currentDocument.getText(selection.range).trim(); |
| 77 | |
| 78 | if (config().get<boolean>('removeLeadingComments')) { |
| 79 | selectedText = removeLeadingComments(selectedText); |
| 80 | } |
| 81 | |
| 82 | selection.selectedText = selectedText; |
| 83 | |
| 84 | return selection; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Like vscode's Position class, but allows negative values. |
no test coverage detected