Add keyboard tab switching

This commit is contained in:
2026-05-07 19:10:04 -04:00
parent c6ddf806d1
commit de68fb6ac3
3 changed files with 104 additions and 2 deletions
+8 -1
View File
@@ -6,7 +6,10 @@ use gpui::{
};
use shell::ElyShell;
actions!(ely_app, [CloseCurrentTab, FocusAddressBar, OpenNewTab, Quit]);
actions!(
ely_app,
[CloseCurrentTab, FocusAddressBar, OpenNewTab, Quit, SelectNextTab, SelectPreviousTab,]
);
fn main() {
Application::new().run(|cx: &mut App| {
@@ -19,6 +22,10 @@ fn main() {
KeyBinding::new("ctrl-l", FocusAddressBar, None),
KeyBinding::new("cmd-w", CloseCurrentTab, None),
KeyBinding::new("ctrl-w", CloseCurrentTab, None),
KeyBinding::new("cmd-shift-]", SelectNextTab, None),
KeyBinding::new("ctrl-tab", SelectNextTab, None),
KeyBinding::new("cmd-shift-[", SelectPreviousTab, None),
KeyBinding::new("ctrl-shift-tab", SelectPreviousTab, None),
KeyBinding::new("cmd-q", Quit, None),
]);
cx.set_menus(vec![
+39 -1
View File
@@ -12,7 +12,7 @@ use gpui_component::{
input::{Input, InputEvent, InputState, SelectAll},
};
use crate::{CloseCurrentTab, FocusAddressBar, OpenNewTab};
use crate::{CloseCurrentTab, FocusAddressBar, OpenNewTab, SelectNextTab, SelectPreviousTab};
enum ShellState {
Ready(BrowserCore),
@@ -94,6 +94,24 @@ impl ElyShell {
}
}
fn select_next_tab(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state
&& core.select_next_tab().is_ok()
{
self.sync_address_input(window, cx);
cx.notify();
}
}
fn select_previous_tab(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state
&& core.select_previous_tab().is_ok()
{
self.sync_address_input(window, cx);
cx.notify();
}
}
fn close_active_tab(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state
&& core.close_active_tab().is_ok()
@@ -125,6 +143,24 @@ impl ElyShell {
self.open_new_tab(window, cx);
}
fn on_select_next_tab(
&mut self,
_: &SelectNextTab,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.select_next_tab(window, cx);
}
fn on_select_previous_tab(
&mut self,
_: &SelectPreviousTab,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.select_previous_tab(window, cx);
}
fn sync_address_input(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let ShellState::Ready(core) = &mut self.state else {
return;
@@ -170,6 +206,8 @@ impl ElyShell {
.on_action(cx.listener(Self::on_close_current_tab))
.on_action(cx.listener(Self::on_focus_address_bar))
.on_action(cx.listener(Self::on_open_new_tab))
.on_action(cx.listener(Self::on_select_next_tab))
.on_action(cx.listener(Self::on_select_previous_tab))
.bg(rgb(ELY_THEME.canvas))
.text_color(rgb(ELY_THEME.ink))
.flex()