Add the ability for tasks to target the center pane (#22004)

Closes #20060
Closes #20720
Closes #19873
Closes #9445

Release Notes:

- Fixed a bug where tasks would be spawned with their working directory
set to a file in some cases
- Added the ability to spawn tasks in the center pane, when spawning
from a keybinding:

```json5
[
  {
    // Assuming you have a task labeled "echo hello"
    "ctrl--": [
      "task::Spawn",
      { "task_name": "echo hello", "target": "center" }
    ]
  }
]
```
This commit is contained in:
Mikayla Maki 2024-12-13 19:39:46 -08:00 committed by GitHub
parent 85c3aec6e7
commit 4f96706161
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 263 additions and 106 deletions

View file

@ -1,15 +1,17 @@
use project::TaskSourceKind;
use remote::ConnectionState;
use task::{ResolvedTask, TaskContext, TaskTemplate};
use task::{NewCenterTask, ResolvedTask, TaskContext, TaskTemplate};
use ui::ViewContext;
use zed_actions::TaskSpawnTarget;
use crate::Workspace;
pub fn schedule_task(
workspace: &Workspace,
workspace: &mut Workspace,
task_source_kind: TaskSourceKind,
task_to_resolve: &TaskTemplate,
task_cx: &TaskContext,
task_target: zed_actions::TaskSpawnTarget,
omit_history: bool,
cx: &mut ViewContext<'_, Workspace>,
) {
@ -27,7 +29,7 @@ pub fn schedule_task(
}
if let Some(spawn_in_terminal) =
task_to_resolve.resolve_task(&task_source_kind.to_id_base(), task_cx)
task_to_resolve.resolve_task(&task_source_kind.to_id_base(), task_target, task_cx)
{
schedule_resolved_task(
workspace,
@ -40,12 +42,13 @@ pub fn schedule_task(
}
pub fn schedule_resolved_task(
workspace: &Workspace,
workspace: &mut Workspace,
task_source_kind: TaskSourceKind,
mut resolved_task: ResolvedTask,
omit_history: bool,
cx: &mut ViewContext<'_, Workspace>,
) {
let target = resolved_task.target;
if let Some(spawn_in_terminal) = resolved_task.resolved.take() {
if !omit_history {
resolved_task.resolved = Some(spawn_in_terminal.clone());
@ -59,6 +62,18 @@ pub fn schedule_resolved_task(
}
});
}
cx.emit(crate::Event::SpawnTask(Box::new(spawn_in_terminal)));
match target {
TaskSpawnTarget::Center => {
cx.dispatch_action(Box::new(NewCenterTask {
action: spawn_in_terminal,
}));
}
TaskSpawnTarget::Dock => {
cx.emit(crate::Event::SpawnTask {
action: Box::new(spawn_in_terminal),
});
}
}
}
}