diff --git a/crates/ely_app/src/main.rs b/crates/ely_app/src/main.rs index 3ac3f09..f0d6171 100644 --- a/crates/ely_app/src/main.rs +++ b/crates/ely_app/src/main.rs @@ -12,6 +12,7 @@ actions!( [ CloseCurrentTab, FocusAddressBar, + FocusCommandMode, OpenDownloads, OpenNewTab, Quit, @@ -40,8 +41,8 @@ fn main() { KeyBinding::new("ctrl-shift-t", RestoreClosedTab, None), KeyBinding::new("cmd-shift-f", ToggleFavoriteTab, None), KeyBinding::new("ctrl-shift-f", ToggleFavoriteTab, None), - KeyBinding::new("cmd-shift-p", TogglePinnedTab, None), - KeyBinding::new("ctrl-shift-p", TogglePinnedTab, None), + KeyBinding::new("cmd-shift-p", FocusCommandMode, None), + KeyBinding::new("ctrl-shift-p", FocusCommandMode, None), KeyBinding::new("cmd-shift-]", SelectNextTab, None), KeyBinding::new("ctrl-tab", SelectNextTab, None), KeyBinding::new("cmd-shift-[", SelectPreviousTab, None), @@ -62,6 +63,8 @@ fn main() { items: vec![ MenuItem::action("New Tab", OpenNewTab), MenuItem::separator(), + MenuItem::action("Command Mode", FocusCommandMode), + MenuItem::separator(), MenuItem::action("Close Tab", CloseCurrentTab), MenuItem::separator(), MenuItem::action("Restore Closed Tab", RestoreClosedTab), diff --git a/crates/ely_app/src/shell/mod.rs b/crates/ely_app/src/shell/mod.rs index cee03ff..584854a 100644 --- a/crates/ely_app/src/shell/mod.rs +++ b/crates/ely_app/src/shell/mod.rs @@ -6,8 +6,8 @@ use gpui::{App, AppContext, Context, Entity, FocusHandle, Focusable, Subscriptio use gpui_component::input::{InputEvent, InputState, SelectAll}; use crate::{ - CloseCurrentTab, FocusAddressBar, OpenDownloads, OpenNewTab, RestoreClosedTab, SelectNextTab, - SelectPreviousTab, ToggleFavoriteTab, TogglePinnedTab, + CloseCurrentTab, FocusAddressBar, FocusCommandMode, OpenDownloads, OpenNewTab, + RestoreClosedTab, SelectNextTab, SelectPreviousTab, ToggleFavoriteTab, TogglePinnedTab, }; enum ShellState { @@ -108,6 +108,18 @@ impl ElyShell { window.dispatch_action(Box::new(SelectAll), cx); } + fn focus_command_mode(&mut self, window: &mut Window, cx: &mut Context) { + if let ShellState::Ready(core) = &mut self.state { + core.set_command_query(">"); + } + + self.command_input.update(cx, |input, cx| { + input.set_value(">", window, cx); + input.focus(window, cx); + }); + cx.notify(); + } + fn select_tab(&mut self, tab_id: &TabId, window: &mut Window, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state && core.select_tab(tab_id).is_ok() @@ -210,6 +222,15 @@ impl ElyShell { self.focus_address_bar(window, cx); } + fn on_focus_command_mode( + &mut self, + _: &FocusCommandMode, + window: &mut Window, + cx: &mut Context, + ) { + self.focus_command_mode(window, cx); + } + fn on_open_new_tab(&mut self, _: &OpenNewTab, window: &mut Window, cx: &mut Context) { self.open_new_tab(window, cx); } diff --git a/crates/ely_app/src/shell/render.rs b/crates/ely_app/src/shell/render.rs index 866dc0c..5973792 100644 --- a/crates/ely_app/src/shell/render.rs +++ b/crates/ely_app/src/shell/render.rs @@ -37,6 +37,7 @@ impl ElyShell { .track_focus(&self.focus_handle) .on_action(cx.listener(Self::on_close_current_tab)) .on_action(cx.listener(Self::on_focus_address_bar)) + .on_action(cx.listener(Self::on_focus_command_mode)) .on_action(cx.listener(Self::on_open_downloads)) .on_action(cx.listener(Self::on_open_new_tab)) .on_action(cx.listener(Self::on_restore_closed_tab))