From 616ea131af6447b4818f1e085537fd01e29098b3 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 19 Dec 2023 12:11:06 -0500 Subject: [PATCH] Style buffer search input (#3713) This PR styles the text input for the buffer search. Release Notes: - N/A --- crates/search2/src/buffer_search.rs | 58 +++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index 5db7aff73670161719188a8cff5051c4a4a46604..17dc13feaa1989f3a3d00be59483f2252ab2afb5 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -7,18 +7,21 @@ use crate::{ ToggleCaseSensitive, ToggleReplace, ToggleWholeWord, }; use collections::HashMap; -use editor::Editor; +use editor::{Editor, EditorElement, EditorStyle}; use futures::channel::oneshot; use gpui::{ - actions, div, impl_actions, red, Action, AppContext, ClickEvent, Div, EventEmitter, - FocusableView, InteractiveElement as _, IntoElement, KeyContext, ParentElement as _, Render, - Styled, Subscription, Task, View, ViewContext, VisualContext as _, WindowContext, + actions, div, impl_actions, Action, AppContext, ClickEvent, Div, EventEmitter, FocusableView, + FontStyle, FontWeight, InteractiveElement as _, IntoElement, KeyContext, ParentElement as _, + Render, Styled, Subscription, Task, TextStyle, View, ViewContext, VisualContext as _, + WhiteSpace, WindowContext, }; use project::search::SearchQuery; use serde::Deserialize; +use settings::Settings; use std::{any::Any, sync::Arc}; +use theme::ThemeSettings; -use ui::{h_stack, ButtonCommon, Clickable, Icon, IconButton, IconElement, Tooltip}; +use ui::{h_stack, prelude::*, Icon, IconButton, IconElement, Tooltip}; use util::ResultExt; use workspace::{ item::ItemHandle, @@ -63,6 +66,38 @@ pub struct BufferSearchBar { replace_enabled: bool, } +impl BufferSearchBar { + fn render_text_input(&self, editor: &View, cx: &ViewContext) -> impl IntoElement { + let settings = ThemeSettings::get_global(cx); + let text_style = TextStyle { + color: if editor.read(cx).read_only() { + cx.theme().colors().text_disabled + } else { + cx.theme().colors().text + }, + font_family: settings.ui_font.family.clone(), + font_features: settings.ui_font.features, + font_size: rems(0.875).into(), + font_weight: FontWeight::NORMAL, + font_style: FontStyle::Normal, + line_height: relative(1.3).into(), + background_color: None, + underline: None, + white_space: WhiteSpace::Normal, + }; + + EditorElement::new( + &editor, + EditorStyle { + background: cx.theme().colors().editor_background, + local_player: cx.theme().players().local(), + text: text_style, + ..Default::default() + }, + ) + } +} + impl EventEmitter for BufferSearchBar {} impl EventEmitter for BufferSearchBar {} impl Render for BufferSearchBar { @@ -207,15 +242,16 @@ impl Render for BufferSearchBar { .w_full() .p_1() .child( - div() - .flex() + h_stack() .flex_1() + .px_2() + .py_1() + .gap_2() .border_1() - .border_color(red()) - .rounded_md() - .items_center() + .border_color(cx.theme().colors().border) + .rounded_lg() .child(IconElement::new(Icon::MagnifyingGlass)) - .child(self.query_editor.clone()) + .child(self.render_text_input(&self.query_editor, cx)) .children(supported_options.case.then(|| { self.render_search_option_button( SearchOptions::CASE_SENSITIVE,