Improve Linux terminal keymap and context menu (#16845)
Follow-up https://github.com/zed-industries/zed/pull/16085 that fixes the search deploy to be actually a part of the terminal-related bindings. Part of https://github.com/zed-industries/zed/issues/16839 Also * fixes few other bindings to use `shift` and avoid conflicts with the existing key bindings. * adds terminal inline assist to the context menu and makes both the menu and the button to dynamically adjust to `assist.enabled` settings change It is still unclear to me, why certain labels for certain bindings are wrong (it's still showing `ctrl-w` for closing the terminal tab, and `shift-insert` instead of `ctrl-shift-v` for Paste, while Insert is near and has a `ctrl-shift-c` binding shown) but at least the keys work now. Release notes: - Improved Linux terminal keymap and context menu
This commit is contained in:
parent
28271a9a36
commit
1a2a538366
11 changed files with 87 additions and 50 deletions
|
@ -33,6 +33,7 @@ use workspace::{
|
|||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use zed_actions::InlineAssist;
|
||||
|
||||
const TERMINAL_PANEL_KEY: &str = "TerminalPanel";
|
||||
|
||||
|
@ -68,7 +69,8 @@ pub struct TerminalPanel {
|
|||
_subscriptions: Vec<Subscription>,
|
||||
deferred_tasks: HashMap<TaskId, Task<()>>,
|
||||
enabled: bool,
|
||||
additional_tab_bar_buttons: Vec<AnyView>,
|
||||
assistant_enabled: bool,
|
||||
assistant_tab_bar_button: Option<AnyView>,
|
||||
}
|
||||
|
||||
impl TerminalPanel {
|
||||
|
@ -154,23 +156,25 @@ impl TerminalPanel {
|
|||
deferred_tasks: HashMap::default(),
|
||||
_subscriptions: subscriptions,
|
||||
enabled,
|
||||
additional_tab_bar_buttons: Vec::new(),
|
||||
assistant_enabled: false,
|
||||
assistant_tab_bar_button: None,
|
||||
};
|
||||
this.apply_tab_bar_buttons(cx);
|
||||
this
|
||||
}
|
||||
|
||||
pub fn register_tab_bar_button(
|
||||
&mut self,
|
||||
button: impl Into<AnyView>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.additional_tab_bar_buttons.push(button.into());
|
||||
pub fn asssistant_enabled(&mut self, enabled: bool, cx: &mut ViewContext<Self>) {
|
||||
self.assistant_enabled = enabled;
|
||||
if enabled {
|
||||
self.assistant_tab_bar_button = Some(cx.new_view(|_| InlineAssistTabBarButton).into());
|
||||
} else {
|
||||
self.assistant_tab_bar_button = None;
|
||||
}
|
||||
self.apply_tab_bar_buttons(cx);
|
||||
}
|
||||
|
||||
fn apply_tab_bar_buttons(&self, cx: &mut ViewContext<Self>) {
|
||||
let additional_buttons = self.additional_tab_bar_buttons.clone();
|
||||
let assistant_tab_bar_button = self.assistant_tab_bar_button.clone();
|
||||
self.pane.update(cx, |pane, cx| {
|
||||
pane.set_render_tab_bar_buttons(cx, move |pane, cx| {
|
||||
if !pane.has_focus(cx) && !pane.context_menu_focused(cx) {
|
||||
|
@ -179,7 +183,7 @@ impl TerminalPanel {
|
|||
let focus_handle = pane.focus_handle(cx);
|
||||
let right_children = h_flex()
|
||||
.gap_2()
|
||||
.children(additional_buttons.clone())
|
||||
.children(assistant_tab_bar_button.clone())
|
||||
.child(
|
||||
PopoverMenu::new("terminal-tab-bar-popover-menu")
|
||||
.trigger(
|
||||
|
@ -686,6 +690,10 @@ impl TerminalPanel {
|
|||
fn has_no_terminals(&self, cx: &WindowContext) -> bool {
|
||||
self.pane.read(cx).items_len() == 0 && self.pending_terminals_to_add == 0
|
||||
}
|
||||
|
||||
pub fn assistant_enabled(&self) -> bool {
|
||||
self.assistant_enabled
|
||||
}
|
||||
}
|
||||
|
||||
async fn wait_for_terminals_tasks(
|
||||
|
@ -851,6 +859,19 @@ impl Panel for TerminalPanel {
|
|||
}
|
||||
}
|
||||
|
||||
struct InlineAssistTabBarButton;
|
||||
|
||||
impl Render for InlineAssistTabBarButton {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
IconButton::new("terminal_inline_assistant", IconName::ZedAssistant)
|
||||
.icon_size(IconSize::Small)
|
||||
.on_click(cx.listener(|_, _, cx| {
|
||||
cx.dispatch_action(InlineAssist::default().boxed_clone());
|
||||
}))
|
||||
.tooltip(move |cx| Tooltip::for_action("Inline Assist", &InlineAssist::default(), cx))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct SerializedTerminalPanel {
|
||||
items: Vec<u64>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue