Move task centering code closer to user input (#22082)
Follow-up of https://github.com/zed-industries/zed/pull/22004 * Reuse center terminals for tasks, when requested * Extend task templates with `RevealTarget`, moving it from `TaskSpawnTarget` into the core library * Use `reveal_target` instead of `target` to avoid misinterpretations in the task template context * Do not expose `SpawnInTerminal` to user interface, avoid it implementing `Serialize` and `Deserialize` * Remove `NewCenterTask` action, extending `task::Spawn` interface instead * Do not require any extra unrelated parameters during task resolution, instead, use task overrides on the resolved tasks on the modal side * Add keybindings for opening the task modal in the `RevealTarget::Center` mode Release Notes: - N/A
This commit is contained in:
parent
ea012075fc
commit
bc113e4b51
17 changed files with 356 additions and 285 deletions
|
@ -1,5 +1,6 @@
|
|||
use gpui::{actions, impl_actions};
|
||||
use serde::Deserialize;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// If the zed binary doesn't use anything in this crate, it will be optimized away
|
||||
// and the actions won't initialize. So we just provide an empty initialization function
|
||||
|
@ -90,33 +91,39 @@ pub struct OpenRecent {
|
|||
gpui::impl_actions!(projects, [OpenRecent]);
|
||||
gpui::actions!(projects, [OpenRemote]);
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Deserialize, Default, Debug)]
|
||||
/// Where to spawn the task in the UI.
|
||||
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TaskSpawnTarget {
|
||||
pub enum RevealTarget {
|
||||
/// In the central pane group, "main" editor area.
|
||||
Center,
|
||||
/// In the terminal dock, "regular" terminal items' place.
|
||||
#[default]
|
||||
Dock,
|
||||
}
|
||||
|
||||
/// Spawn a task with name or open tasks modal
|
||||
#[derive(PartialEq, Clone, Deserialize, Default)]
|
||||
pub struct Spawn {
|
||||
#[serde(default)]
|
||||
/// Name of the task to spawn.
|
||||
/// If it is not set, a modal with a list of available tasks is opened instead.
|
||||
/// Defaults to None.
|
||||
pub task_name: Option<String>,
|
||||
/// Which part of the UI the task should be spawned in.
|
||||
/// Defaults to Dock.
|
||||
#[serde(default)]
|
||||
pub target: Option<TaskSpawnTarget>,
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum Spawn {
|
||||
/// Spawns a task by the name given.
|
||||
ByName {
|
||||
task_name: String,
|
||||
#[serde(default)]
|
||||
reveal_target: Option<RevealTarget>,
|
||||
},
|
||||
/// Spawns a task via modal's selection.
|
||||
ViaModal {
|
||||
/// Selected task's `reveal_target` property override.
|
||||
#[serde(default)]
|
||||
reveal_target: Option<RevealTarget>,
|
||||
},
|
||||
}
|
||||
|
||||
impl Spawn {
|
||||
pub fn modal() -> Self {
|
||||
Self {
|
||||
task_name: None,
|
||||
target: None,
|
||||
Self::ViaModal {
|
||||
reveal_target: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue