Add search engine settings

This commit is contained in:
2026-05-08 03:04:33 -04:00
parent 3a1c415572
commit 6750f60d52
11 changed files with 334 additions and 12 deletions
@@ -8,6 +8,7 @@ mod plugin_details;
mod plugins;
mod profiles;
mod reading_list;
mod search;
mod settings;
mod shortcuts;
mod sidebar_tabs;
@@ -51,6 +52,7 @@ impl ElyShell {
"ely://about" => self.render_about_page(snapshot),
"ely://settings" => self.render_settings_page(snapshot, cx),
"ely://settings/sidebar-tabs" => self.render_sidebar_tabs_page(snapshot, cx),
"ely://settings/search" => self.render_search_page(snapshot, cx),
"ely://settings/spaces" => self.render_spaces_page(snapshot, cx),
"ely://settings/shortcuts" => self.render_shortcuts_page(snapshot),
"ely://settings/plugins" => self.render_plugins_page(snapshot, cx),
@@ -0,0 +1,204 @@
use ely_browser_core::BrowserSnapshot;
use ely_design_system::colors;
use ely_domain::SearchEngine;
use gpui::{AnyElement, Context, IntoElement, ParentElement, Styled, div, px, rgb};
use gpui_component::{
IconName, Selectable, Sizable, StyledExt,
button::{Button, ButtonVariants},
scroll::ScrollableElement,
};
use super::{ElyShell, render_canvas_surface};
impl ElyShell {
pub(super) fn render_search_page(
&mut self,
snapshot: &BrowserSnapshot,
cx: &mut Context<Self>,
) -> AnyElement {
render_canvas_surface(
div()
.size_full()
.p_8()
.flex()
.flex_col()
.gap_5()
.child(render_search_header(snapshot))
.child(render_search_summary(snapshot.search_engine))
.child(render_search_engines(snapshot.search_engine, cx)),
)
}
}
fn render_search_header(snapshot: &BrowserSnapshot) -> AnyElement {
div()
.flex()
.items_end()
.justify_between()
.gap_4()
.child(
div()
.min_w_0()
.flex()
.flex_col()
.gap_2()
.child(div().text_size(px(26.0)).text_color(rgb(colors::INK)).child("Search"))
.child(
div()
.text_sm()
.truncate()
.text_color(rgb(colors::MUTED))
.child(format!("Profile: {}", snapshot.active_profile_name)),
),
)
.child(
div()
.flex()
.items_center()
.gap_2()
.text_xs()
.font_semibold()
.text_color(rgb(colors::MUTED))
.child(IconName::Search)
.child(snapshot.search_engine.name()),
)
.into_any_element()
}
fn render_search_summary(search_engine: SearchEngine) -> AnyElement {
div()
.rounded_md()
.border_1()
.border_color(rgb(colors::HAIRLINE))
.bg(rgb(colors::CANVAS_SOFT))
.px_4()
.py_3()
.flex()
.items_center()
.justify_between()
.gap_4()
.child(
div()
.min_w_0()
.flex()
.items_center()
.gap_3()
.child(div().text_color(rgb(colors::PRIMARY)).child(IconName::Search))
.child(
div()
.min_w_0()
.flex()
.flex_col()
.gap_1()
.child(
div()
.text_sm()
.font_semibold()
.text_color(rgb(colors::INK))
.child(search_engine.name()),
)
.child(
div()
.text_xs()
.truncate()
.text_color(rgb(colors::MUTED))
.child(search_engine.host()),
),
),
)
.child(
div().text_xs().font_semibold().text_color(rgb(colors::SUCCESS)).child("Saved locally"),
)
.into_any_element()
}
fn render_search_engines(active_engine: SearchEngine, cx: &mut Context<ElyShell>) -> AnyElement {
div()
.flex_1()
.min_h_0()
.flex()
.flex_col()
.overflow_y_scrollbar()
.border_t_1()
.border_color(rgb(colors::HAIRLINE))
.children(SearchEngine::ALL.iter().copied().enumerate().map(|(index, search_engine)| {
render_search_engine_row(index, search_engine, active_engine, cx)
}))
.into_any_element()
}
fn render_search_engine_row(
index: usize,
search_engine: SearchEngine,
active_engine: SearchEngine,
cx: &mut Context<ElyShell>,
) -> AnyElement {
let selected = search_engine == active_engine;
div()
.py_3()
.border_b_1()
.border_color(rgb(colors::HAIRLINE))
.flex()
.items_center()
.justify_between()
.gap_4()
.child(
div()
.min_w_0()
.flex()
.items_center()
.gap_3()
.child(
div()
.text_color(rgb(search_engine_icon_color(selected)))
.child(search_engine_icon(selected)),
)
.child(
div()
.min_w_0()
.flex()
.flex_col()
.gap_1()
.child(
div()
.text_sm()
.font_semibold()
.truncate()
.text_color(rgb(colors::INK))
.child(search_engine.name()),
)
.child(
div()
.text_xs()
.truncate()
.text_color(rgb(colors::MUTED))
.child(search_engine.host()),
),
),
)
.child(
Button::new(("search-engine", index))
.ghost()
.xsmall()
.selected(selected)
.label(search_engine_button_label(selected))
.tooltip(search_engine.name())
.on_click(cx.listener(move |shell, _, _, cx| {
shell.set_search_engine(search_engine, cx);
})),
)
.into_any_element()
}
fn search_engine_icon(selected: bool) -> IconName {
if selected { IconName::CircleCheck } else { IconName::Globe }
}
fn search_engine_icon_color(selected: bool) -> u32 {
if selected { colors::PRIMARY } else { colors::MUTED_SOFT }
}
fn search_engine_button_label(selected: bool) -> &'static str {
if selected { "Active" } else { "Select" }
}
@@ -30,6 +30,12 @@ const SETTINGS_ROUTES: &[SettingsRoute] = &[
detail: "Space identity, accent color, and active context.",
route: "ely://settings/spaces",
},
SettingsRoute {
icon: IconName::Search,
title: "Search",
detail: "Default search engine for Command Bar queries.",
route: "ely://settings/search",
},
SettingsRoute {
icon: IconName::CircleUser,
title: "Profiles",
+8 -1
View File
@@ -6,7 +6,7 @@ mod site_permissions;
mod splits;
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
use ely_domain::{ArchivePolicy, CommandIntent, ProfileId, SpaceId, TabId, UrlText};
use ely_domain::{ArchivePolicy, CommandIntent, ProfileId, SearchEngine, SpaceId, TabId, UrlText};
use gpui::{App, AppContext, Context, Entity, FocusHandle, Focusable, Subscription, Window};
use gpui_component::input::{InputEvent, InputState, SelectAll};
@@ -264,6 +264,13 @@ impl ElyShell {
}
}
fn set_search_engine(&mut self, search_engine: SearchEngine, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state {
core.set_search_engine(search_engine);
cx.notify();
}
}
fn archive_idle_tabs_now(&mut self, cx: &mut Context<Self>) {
if let ShellState::Ready(core) = &mut self.state
&& core.archive_idle_tabs(std::time::SystemTime::now()).is_ok()