Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: double-click to run #129

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading