Skip to content

Commit

Permalink
feat: double-click to run
Browse files Browse the repository at this point in the history
  • Loading branch information
pd93 committed Apr 5, 2024
1 parent c932816 commit c006fdc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@
"default": true,
"description": "Check if there is a newer version of Task on startup."
},
"doubleClickToRun": {
"type": "number",
"default": 500,
"description": "The double-click timeout for a task in the tree view. To disable double-click to run, set this to 0."
},
"tree": {
"type": "object",
"description": "Tree view configuration options.",
Expand Down
15 changes: 15 additions & 0 deletions src/services/taskfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class TaskfileService {
private lastTaskName: string | undefined;
private lastTaskDir: string | undefined;
private version: semver.SemVer | undefined;
private previousSelection: string | undefined;
private previousSelectionTimestamp: number | undefined;

private constructor() {
TaskfileService.outputChannel = vscode.window.createOutputChannel('Task');
Expand Down Expand Up @@ -280,6 +282,16 @@ class TaskfileService {
}

public async goToDefinition(task: models.Task, preview: boolean = false): Promise<void> {
const currentTime = Date.now();
const doubleClicked = this.previousSelection !== undefined && this.previousSelectionTimestamp !== undefined
&& this.previousSelection === task.name
&& (currentTime - this.previousSelectionTimestamp) < settings.doubleClickToRun;
if (doubleClicked) {
this.previousSelection = undefined;
this.previousSelectionTimestamp = undefined;
return this.runTask(task.name);
}

log.info(`Navigating to "${task.name}" definition in: "${task.location.taskfile}"`);

let position = new vscode.Position(task.location.line - 1, task.location.column - 1);
Expand All @@ -300,6 +312,9 @@ class TaskfileService {
} catch (err) {
log.error(err);
}

this.previousSelection = task.name;
this.previousSelectionTimestamp = currentTime;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Settings {
public path!: string;
public outputTo!: OutputTo;
public checkForUpdates!: boolean;
public doubleClickToRun!: number;
public tree!: TreeSettings;
public terminal!: TerminalSettings;

Expand All @@ -30,6 +31,7 @@ class Settings {
this.path = config.get("path") ?? "task";
this.outputTo = config.get("outputTo") ?? OutputTo.output;
this.checkForUpdates = config.get("checkForUpdates") ?? true;
this.doubleClickToRun = config.get("doubleClickToRun") ?? 500;
this.tree = new TreeSettings();
this.terminal = new TerminalSettings();
}
Expand Down

0 comments on commit c006fdc

Please sign in to comment.