tasks: Add editor: Spawn Nearest Task
action (#19901)
This spawns the runnable task that that's closest to the cursor. One thing missing right now is that it doesn't find tasks that are attached to non-outline symbols, such as subtests in Go. Release Notes: - Added a new reveal option for tasks: `"no_focus"`. If used, the tasks terminal panel will be opened and shown, but not focused. - Added a new `editor: spawn nearest task` action that spawns the task with a run indicator icon nearest to the cursor. It can be configured to also use a `reveal` strategy. Example: ```json { "context": "EmptyPane || SharedScreen || vim_mode == normal", "bindings": { ", r t": ["editor::SpawnNearestTask", { "reveal": "no_focus" }], } } ``` Demo: https://github.com/user-attachments/assets/0d1818f0-7ae4-4200-8c3e-0ed47550c298 --------- Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
parent
633b665379
commit
293e080f03
8 changed files with 259 additions and 38 deletions
|
@ -575,9 +575,9 @@ impl TerminalPanel {
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn activate_terminal_view(&self, item_index: usize, cx: &mut WindowContext) {
|
||||
fn activate_terminal_view(&self, item_index: usize, focus: bool, cx: &mut WindowContext) {
|
||||
self.pane.update(cx, |pane, cx| {
|
||||
pane.activate_item(item_index, true, true, cx)
|
||||
pane.activate_item(item_index, true, focus, cx)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -616,8 +616,14 @@ impl TerminalPanel {
|
|||
pane.add_item(terminal_view, true, focus, None, cx);
|
||||
});
|
||||
|
||||
if reveal_strategy == RevealStrategy::Always {
|
||||
workspace.focus_panel::<Self>(cx);
|
||||
match reveal_strategy {
|
||||
RevealStrategy::Always => {
|
||||
workspace.focus_panel::<Self>(cx);
|
||||
}
|
||||
RevealStrategy::NoFocus => {
|
||||
workspace.open_panel::<Self>(cx);
|
||||
}
|
||||
RevealStrategy::Never => {}
|
||||
}
|
||||
Ok(terminal)
|
||||
})?;
|
||||
|
@ -698,7 +704,7 @@ impl TerminalPanel {
|
|||
|
||||
match reveal {
|
||||
RevealStrategy::Always => {
|
||||
self.activate_terminal_view(terminal_item_index, cx);
|
||||
self.activate_terminal_view(terminal_item_index, true, cx);
|
||||
let task_workspace = self.workspace.clone();
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
task_workspace
|
||||
|
@ -707,6 +713,16 @@ impl TerminalPanel {
|
|||
})
|
||||
.detach();
|
||||
}
|
||||
RevealStrategy::NoFocus => {
|
||||
self.activate_terminal_view(terminal_item_index, false, cx);
|
||||
let task_workspace = self.workspace.clone();
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
task_workspace
|
||||
.update(&mut cx, |workspace, cx| workspace.open_panel::<Self>(cx))
|
||||
.ok()
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
RevealStrategy::Never => {}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue