GPUI Box GitHub

Components / controls

FindReplace view

A SearchField with a replacement field and the two replace actions.

A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).

use gpui_kit::controls::search::FindReplace;

Reviewed in find-replace.

Construct
new(ident: impl Into<Ident>, window: &mut Window, cx: &mut Context<Self>) -> Self
Commands

Need a Context, so they need a view.

set_count(count: HitCount, cx: &mut Context<Self>)
set_control_size(size: ControlSize, cx: &mut Context<Self>)
set_disabled(disabled: bool, cx: &mut Context<Self>)
Queries

Only answer; they change nothing.

search_field() -> &Entity<SearchField>
replacement_input() -> &Entity<TextInput>
count(cx: &App) -> HitCount
replacement_text(cx: &App) -> SharedString
is_disabled() -> bool
Reports

The variants of the event it emits. It never applies the change itself.

  • Search
  • ReplacementChanged
  • ReplaceOne
  • ReplaceAll
  • Close
Example · find-replace
fn find_replace(window: &mut Window, cx: &mut App) -> AnyElement {
    ensure_search(window, cx);
    let replace = cx.global::<SceneSearch>().replace.clone();
    let theme = cx.theme().clone();
    stack(&theme)
        .w(px(620.0))
        // Replace all says how many before it does any, so nobody agrees to a
        // number they were never shown.
        .child(caption(
            &theme,
            "replace all names its count before it acts",
        ))
        .child(replace)
        .into_any_element()
}

Source: crates/gpui-kit/src/controls/search.rs