Skip to content

Commit c006fdc

Browse files
committed
feat: double-click to run
1 parent c932816 commit c006fdc

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@
293293
"default": true,
294294
"description": "Check if there is a newer version of Task on startup."
295295
},
296+
"doubleClickToRun": {
297+
"type": "number",
298+
"default": 500,
299+
"description": "The double-click timeout for a task in the tree view. To disable double-click to run, set this to 0."
300+
},
296301
"tree": {
297302
"type": "object",
298303
"description": "Tree view configuration options.",

src/services/taskfile.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class TaskfileService {
3838
private lastTaskName: string | undefined;
3939
private lastTaskDir: string | undefined;
4040
private version: semver.SemVer | undefined;
41+
private previousSelection: string | undefined;
42+
private previousSelectionTimestamp: number | undefined;
4143

4244
private constructor() {
4345
TaskfileService.outputChannel = vscode.window.createOutputChannel('Task');
@@ -280,6 +282,16 @@ class TaskfileService {
280282
}
281283

282284
public async goToDefinition(task: models.Task, preview: boolean = false): Promise<void> {
285+
const currentTime = Date.now();
286+
const doubleClicked = this.previousSelection !== undefined && this.previousSelectionTimestamp !== undefined
287+
&& this.previousSelection === task.name
288+
&& (currentTime - this.previousSelectionTimestamp) < settings.doubleClickToRun;
289+
if (doubleClicked) {
290+
this.previousSelection = undefined;
291+
this.previousSelectionTimestamp = undefined;
292+
return this.runTask(task.name);
293+
}
294+
283295
log.info(`Navigating to "${task.name}" definition in: "${task.location.taskfile}"`);
284296

285297
let position = new vscode.Position(task.location.line - 1, task.location.column - 1);
@@ -300,6 +312,9 @@ class TaskfileService {
300312
} catch (err) {
301313
log.error(err);
302314
}
315+
316+
this.previousSelection = task.name;
317+
this.previousSelectionTimestamp = currentTime;
303318
}
304319
}
305320

src/utils/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Settings {
77
public path!: string;
88
public outputTo!: OutputTo;
99
public checkForUpdates!: boolean;
10+
public doubleClickToRun!: number;
1011
public tree!: TreeSettings;
1112
public terminal!: TerminalSettings;
1213

@@ -30,6 +31,7 @@ class Settings {
3031
this.path = config.get("path") ?? "task";
3132
this.outputTo = config.get("outputTo") ?? OutputTo.output;
3233
this.checkForUpdates = config.get("checkForUpdates") ?? true;
34+
this.doubleClickToRun = config.get("doubleClickToRun") ?? 500;
3335
this.tree = new TreeSettings();
3436
this.terminal = new TerminalSettings();
3537
}

0 commit comments

Comments
 (0)