gui: one header_search_field for Notes and Documents

Both screens framed their bare search input in header_search and showed
header_search_clear while it held a query, identically apart from the id and
what clearing does. components::screen_header::header_search_field is that
field once. Render-identical. The PDF library's header search has no clear
button, so it keeps its own frame (a decision, see handoff).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Greg ShuflinandClaude Opus 5.5 committed 2026-09-28 14:55:09 -07:00
1 parent 82d129f9a6
commit 9854ba295f
3 files changed
+39 -27

No files matched your search

+10 -14
View File
@@ -23,9 +23,7 @@ use crate::components::button::{OnClickIf, button};
use crate::components::import_prompt::{ImportPrompt, ImportPromptToggle, render_import_prompt};
use crate::components::import_trigger::{FilePicker, import_trigger};
use crate::components::menu::{DropdownMenu, PopupMenuItem, dropdown_trigger as filter_trigger};
use crate::components::screen_header::{
header_search, header_search_clear, screen_header, screen_title,
};
use crate::components::screen_header::{header_search_field, screen_header, screen_title};
use crate::components::spinner::spinner;
use crate::components::table::{CellText, Column, ColumnSizes};
use crate::components::toggle::toggle_row;
@@ -124,17 +122,15 @@ impl DocumentsView {
theme: &Theme,
cx: &mut Context<Self>,
) -> impl IntoElement + use<> {
let has_query = !self.search.read(cx).content().trim().is_empty();
header_search(theme).child(div().flex_1().min_w(px(0.)).child(self.search.clone())).when(
has_query,
|c| {
c.child(header_search_clear(theme, "search-clear").on_click(cx.listener(
|this, _, _, cx| {
this.search.update(cx, |i, cx| i.clear(cx));
this.on_filters_changed(cx);
},
)))
},
header_search_field(
theme,
&self.search,
"search-clear",
cx.listener(|this, _, _, cx| {
this.search.update(cx, |i, cx| i.clear(cx));
this.on_filters_changed(cx);
}),
cx,
)
}
+9 -12
View File
@@ -7,15 +7,15 @@
//! holds — and one layout shape across all three agents is worth more than a
//! seam here.
//!
//! Its frame is [`header_search`], which is what makes it the same field
//! Its frame is [`header_search`](crate::components::screen_header::header_search), which is what makes it the same field
//! Documents and the PDF library put in the same place (ADR 0032 §5) — and why
//! the input inside it is [`TextInput::bare`]: the frame already draws the box,
//! so a second bordered, padded box nested inside it would both double the
//! chrome and eat the width the field is there to give the text.
use gpui::{Context, Entity, IntoElement, div, prelude::*, px};
use gpui::{Context, Entity, IntoElement, prelude::*};
use crate::components::screen_header::{header_search, header_search_clear};
use crate::components::screen_header::header_search_field;
use crate::components::text_input::{InputEvent, TextInput};
use crate::theme::Theme;
@@ -62,15 +62,12 @@ impl NotesView {
theme: &Theme,
cx: &mut Context<Self>,
) -> impl IntoElement + use<> {
let has_query = !self.search.read(cx).content().trim().is_empty();
header_search(theme).child(div().flex_1().min_w(px(0.)).child(self.search.clone())).when(
has_query,
|c| {
c.child(
header_search_clear(theme, "notes-search-clear")
.on_click(cx.listener(|this, _, _, cx| this.clear_search(cx))),
)
},
header_search_field(
theme,
&self.search,
"notes-search-clear",
cx.listener(|this, _, _, cx| this.clear_search(cx)),
cx,
)
}
}
+20 -1
View File
@@ -17,9 +17,12 @@
//! Everything is optional except the title, so a screen with no search and no
//! actions still gets the same bar at the same height.
use gpui::{Div, SharedString, Stateful, div, prelude::*, px, svg};
use gpui::{
App, ClickEvent, Div, Entity, SharedString, Stateful, Window, div, prelude::*, px, svg,
};
use crate::assets::Icon;
use crate::components::text_input::TextInput;
use crate::components::truncate::TruncateMiddle;
use crate::sizing::{control, font, icon, shape};
use crate::theme::Theme;
@@ -106,6 +109,22 @@ pub fn header_search(theme: &Theme) -> Div {
.child(svg().path(Icon::Search).size(icon::SM).flex_none().text_color(theme.text_tertiary))
}
/// [`header_search`] around a bare `input`, with [`header_search_clear`]
/// shown while the field holds a query. `on_clear` empties the field and
/// whatever it was narrowing.
pub fn header_search_field(
theme: &Theme,
input: &Entity<TextInput>,
clear_id: &'static str,
on_clear: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
cx: &App,
) -> Div {
let has_query = !input.read(cx).content().trim().is_empty();
header_search(theme)
.child(div().flex_1().min_w(px(0.)).child(input.clone()))
.when(has_query, |c| c.child(header_search_clear(theme, clear_id).on_click(on_clear)))
}
/// The search field's trailing clear button: empties the field and, with it,
/// whatever the field was narrowing.
///