Skip to content

Commit

Permalink
Improved text selection behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Bradley <[email protected]>
  • Loading branch information
jgbradley1 authored and akosyakov committed Mar 20, 2019
1 parent a3c7420 commit d03bddc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,20 @@ export class TaskService implements TaskConfigurationClient {
}

/**
* Run the selected text lines in active terminal.
* Run selected text in the last active terminal.
*/
async runSelectedText(): Promise<void> {
if (!this.editorManager.currentEditor) { return; }
const startLine = this.editorManager.currentEditor.editor.selection.start.line;
const startCharacter = this.editorManager.currentEditor.editor.selection.start.character;
const endLine = this.editorManager.currentEditor.editor.selection.end.line;
const selectedRange: Range = Range.create(startLine, 0, endLine + 1, 0);
const selectedText = this.editorManager.currentEditor.editor.document.getText(selectedRange);
const endCharacter = this.editorManager.currentEditor.editor.selection.end.character;
let selectedRange: Range = Range.create(startLine, startCharacter, endLine, endCharacter);
// if no text is selected, default to selecting entire line
if (startLine === endLine && startCharacter === endCharacter) {
selectedRange = Range.create(startLine, 0, endLine + 1, 0);
}
const selectedText: string = this.editorManager.currentEditor.editor.document.getText(selectedRange).trimRight() + '\n';
let terminal = this.terminalService.currentTerminal;
if (!terminal) {
terminal = <TerminalWidget>await this.terminalService.newTerminal(<TerminalWidgetFactoryOptions>{ created: new Date().toString() });
Expand Down

0 comments on commit d03bddc

Please sign in to comment.