diff --git a/package.json b/package.json index ce33cfa..9a54563 100644 --- a/package.json +++ b/package.json @@ -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.", diff --git a/src/services/taskfile.ts b/src/services/taskfile.ts index edfdb9f..43c577d 100644 --- a/src/services/taskfile.ts +++ b/src/services/taskfile.ts @@ -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'); @@ -280,6 +282,16 @@ class TaskfileService { } public async goToDefinition(task: models.Task, preview: boolean = false): Promise { + 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); @@ -300,6 +312,9 @@ class TaskfileService { } catch (err) { log.error(err); } + + this.previousSelection = task.name; + this.previousSelectionTimestamp = currentTime; } } diff --git a/src/utils/settings.ts b/src/utils/settings.ts index cab1b82..5541fe1 100644 --- a/src/utils/settings.ts +++ b/src/utils/settings.ts @@ -7,6 +7,7 @@ class Settings { public path!: string; public outputTo!: OutputTo; public checkForUpdates!: boolean; + public doubleClickToRun!: number; public tree!: TreeSettings; public terminal!: TerminalSettings; @@ -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(); }