From e600e71c1c4dd212f759d803e5f8cfe146425538 Mon Sep 17 00:00:00 2001 From: Dino Date: Wed, 5 Mar 2025 15:47:49 +0000 Subject: [PATCH] vim: Fix tab title when using `!!` and disable rerun button for terminal tasks (#26122) These changes tackle two issues with running terminal commands via vim mode: - When using `!!` the tab's title was set to `!!` instead of the previous command that was run and these changes fix that in order to always display the previous command in the tab's title when re-running the command with `!!` - For a terminal command, pressing the rerun button would actually bring up the task palette, so this has been updated in order to disable the rerun button when the terminal tab was spawned via a vim command Closes #25800 Release Notes: - Fixed the terminal tab title when using `!!` to rerun the last command - Improved the terminal tab for when command is run via vim mode, in order to disable the rerun button, seeing as Zed does not support it --- crates/project/src/terminals.rs | 1 + crates/task/src/lib.rs | 2 + crates/task/src/task_template.rs | 1 + crates/terminal/src/terminal.rs | 1 + crates/terminal_view/src/terminal_view.rs | 61 +++++++++++++---------- crates/vim/src/command.rs | 7 +-- 6 files changed, 44 insertions(+), 29 deletions(-) diff --git a/crates/project/src/terminals.rs b/crates/project/src/terminals.rs index cd64793603..66f625a50f 100644 --- a/crates/project/src/terminals.rs +++ b/crates/project/src/terminals.rs @@ -273,6 +273,7 @@ impl Project { status: TaskStatus::Running, show_summary: spawn_task.show_summary, show_command: spawn_task.show_command, + show_rerun: spawn_task.show_rerun, completion_rx, }); diff --git a/crates/task/src/lib.rs b/crates/task/src/lib.rs index 0470e1e3a2..70e6597a43 100644 --- a/crates/task/src/lib.rs +++ b/crates/task/src/lib.rs @@ -58,6 +58,8 @@ pub struct SpawnInTerminal { pub show_summary: bool, /// Whether to show the command line in the task output. pub show_command: bool, + /// Whether to show the rerun button in the terminal tab. + pub show_rerun: bool, } /// A final form of the [`TaskTemplate`], that got resolved with a particular [`TaskContext`] and now is ready to spawn the actual task. diff --git a/crates/task/src/task_template.rs b/crates/task/src/task_template.rs index a25e407f10..84f762638c 100644 --- a/crates/task/src/task_template.rs +++ b/crates/task/src/task_template.rs @@ -255,6 +255,7 @@ impl TaskTemplate { shell: self.shell.clone(), show_summary: self.show_summary, show_command: self.show_command, + show_rerun: true, }), }) } diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 4658eb3643..e256366fe4 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -643,6 +643,7 @@ pub struct TaskState { pub hide: HideStrategy, pub show_summary: bool, pub show_command: bool, + pub show_rerun: bool, } /// A status of the current terminal tab's task. diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index bf371773b7..203620a5cb 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -22,8 +22,8 @@ use terminal::{ }, terminal_settings::{self, CursorShape, TerminalBlink, TerminalSettings, WorkingDirectory}, Clear, Copy, Event, MaybeNavigationTarget, Paste, ScrollLineDown, ScrollLineUp, ScrollPageDown, - ScrollPageUp, ScrollToBottom, ScrollToTop, ShowCharacterPalette, TaskStatus, Terminal, - TerminalBounds, ToggleViMode, + ScrollPageUp, ScrollToBottom, ScrollToTop, ShowCharacterPalette, TaskState, TaskStatus, + Terminal, TerminalBounds, ToggleViMode, }; use terminal_element::{is_blank, TerminalElement}; use terminal_panel::TerminalPanel; @@ -807,6 +807,33 @@ impl TerminalView { .children(Scrollbar::vertical(self.scrollbar_state.clone())), ) } + + fn rerun_button(task: &TaskState) -> Option { + if !task.show_rerun { + return None; + } + + let task_id = task.id.clone(); + Some( + IconButton::new("rerun-icon", IconName::Rerun) + .icon_size(IconSize::Small) + .size(ButtonSize::Compact) + .icon_color(Color::Default) + .shape(ui::IconButtonShape::Square) + .tooltip(Tooltip::text("Rerun task")) + .on_click(move |_, window, cx| { + window.dispatch_action( + Box::new(zed_actions::Rerun { + task_id: Some(task_id.0.clone()), + allow_concurrent_runs: Some(true), + use_new_terminal: Some(false), + reevaluate_context: false, + }), + cx, + ); + }), + ) + } } fn subscribe_for_terminal_events( @@ -1220,44 +1247,26 @@ impl Item for TerminalView { fn tab_content(&self, params: TabContentParams, _window: &Window, cx: &App) -> AnyElement { let terminal = self.terminal().read(cx); let title = terminal.title(true); - let rerun_button = |task_id: task::TaskId| { - IconButton::new("rerun-icon", IconName::Rerun) - .icon_size(IconSize::Small) - .size(ButtonSize::Compact) - .icon_color(Color::Default) - .shape(ui::IconButtonShape::Square) - .tooltip(Tooltip::text("Rerun task")) - .on_click(move |_, window, cx| { - window.dispatch_action( - Box::new(zed_actions::Rerun { - task_id: Some(task_id.0.clone()), - allow_concurrent_runs: Some(true), - use_new_terminal: Some(false), - reevaluate_context: false, - }), - cx, - ); - }) - }; let (icon, icon_color, rerun_button) = match terminal.task() { Some(terminal_task) => match &terminal_task.status { TaskStatus::Running => ( IconName::Play, Color::Disabled, - Some(rerun_button(terminal_task.id.clone())), + TerminalView::rerun_button(&terminal_task), ), TaskStatus::Unknown => ( IconName::Warning, Color::Warning, - Some(rerun_button(terminal_task.id.clone())), + TerminalView::rerun_button(&terminal_task), ), TaskStatus::Completed { success } => { - let rerun_button = rerun_button(terminal_task.id.clone()); + let rerun_button = TerminalView::rerun_button(&terminal_task); + if *success { - (IconName::Check, Color::Success, Some(rerun_button)) + (IconName::Check, Color::Success, rerun_button) } else { - (IconName::XCircle, Color::Error, Some(rerun_button)) + (IconName::XCircle, Color::Error, rerun_button) } } }, diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rs index 2c3b028f56..88adcb1855 100644 --- a/crates/vim/src/command.rs +++ b/crates/vim/src/command.rs @@ -1420,11 +1420,11 @@ impl ShellExec { cx.emit(workspace::Event::SpawnTask { action: Box::new(SpawnInTerminal { id: TaskId("vim".to_string()), - full_label: self.command.clone(), - label: self.command.clone(), + full_label: command.clone(), + label: command.clone(), command: command.clone(), args: Vec::new(), - command_label: self.command.clone(), + command_label: command.clone(), cwd, env: HashMap::default(), use_new_terminal: true, @@ -1435,6 +1435,7 @@ impl ShellExec { shell, show_summary: false, show_command: false, + show_rerun: false, }), }); });