Skip to content

feat(input): expose editor search api for custom uis - #2533

Open
calmondev wants to merge 2 commits into
longbridge:mainfrom
calmondev:feat/input-search-api
Open

feat(input): expose editor search api for custom uis#2533
calmondev wants to merge 2 commits into
longbridge:mainfrom
calmondev:feat/input-search-api

Conversation

@calmondev

@calmondev calmondev commented Jul 4, 2026

Copy link
Copy Markdown

Description

I'm building a project that needs a more customized code editor experience. One of the first places where I needed that customization was search. I wanted to keep the editor's matching, highlighting, scrolling, and replace behavior, but render my own search UI.

While looking into the current API, I found that search could only really be enabled or disabled through .searchable(true). The built-in panel works well, but there was no practical public API for building a custom search UI on top of the same editor behavior. This PR adds that missing API surface without exposing the built-in SearchPanel.

Added APIs include:

  • set_search_query(...)
  • clear_search(...)
  • search_next(...)
  • search_previous(...)
  • search_match_count(...)
  • current_search_match_index(...)
  • replace_current_search_match(...)
  • replace_all_search_matches(...)
    • It now converts the full replacement range through range_to_utf16(...). replace_text_in_range_silent(...) expects UTF-16 ranges, and this keeps replace-all consistent with the individual replace path and the other editor callers. For a full-document range, the previous 0..state.text.len() value would generally still clamp to the document end, so this is a consistency/safety cleanup rather than a confirmed bug fix.

Other changes:

  • Search matching state now lives on InputState, so the built-in panel and custom UIs use the same search state.
  • When .searchable(false) is set, the input does not register its built-in Search action handler, so parent UIs can handle Ctrl+F/Cmd+F themselves.
  • SearchPanel and SearchMatcher remain private to the input module.
  • The scroll-direction helpers were moved off SearchPanel into private functions in search.rs.

This PR also adds a compact custom search example in crates/story/examples/custom_search.rs and updates the English editor docs. The Chinese docs were intentionally left unchanged so the translation can be handled by someone who can validate the wording (I don't know Chinese 😞 ).

Screenshot

The custom search example:

image

Break Changes

None.

How to Test

Ran the focused search tests:

cargo test -p gpui-component input::search

This includes test_builtin_search_panel_updates_editor_search, which makes sure the built-in search panel still updates search state after moving the matcher state onto InputState.

Checked the custom search example compiles:

cargo check -p gpui-component-story --example custom_search

Checked the main component crate compiles:

cargo check -p gpui-component

Checked formatting/whitespace in the diff:

git diff --check

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
  • Passed cargo run for story tests related to the changes.
  • Tested macOS, Windows and Linux platforms performance (if the change is platform-specific)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant