Files
zed/crates/ui_input/src/ui_input.rs
T
5bf85b2149 text_finder: Send selected word to text finder query (#59766)
## Objective

Make text finder match project search and buffer search by
pre-populating its query from the active editor according to
`seed_search_query_from_cursor`.

## Solution

- Seed text finder from the active editor's query suggestion when
opening it.
- Pass the seeded query into the picker and select the query text so
typing replaces it immediately.

## Testing

- Manually tested visually by opening text finder from an editor with a
selection and with the cursor on text, confirming the query is
pre-populated and selected.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:
- Improved text finder to seed its query from the active editor.

Co-authored-by: ozacod <ozacod@users.noreply.github.com>
Co-authored-by: Yara 🏳️‍⚧️ <git@yara.blue>
2026-06-23 15:31:18 +00:00

46 lines
1.5 KiB
Rust

//! This crate provides UI components that can be used for form-like scenarios, such as a input and number field.
//!
//! It can't be located in the `ui` crate because it depends on `editor`.
//!
mod input_field;
use std::{
any::Any,
sync::{Arc, OnceLock},
};
use gpui::{FocusHandle, Subscription};
pub use input_field::*;
use ui::{AnyElement, App, Window};
pub trait ErasedEditor: 'static {
fn text(&self, cx: &App) -> String;
fn set_text(&self, text: &str, window: &mut Window, cx: &mut App);
fn clear(&self, window: &mut Window, cx: &mut App);
fn set_placeholder_text(&self, text: &str, window: &mut Window, _: &mut App);
fn move_selection_to_end(&self, window: &mut Window, _: &mut App);
fn select_all(&self, window: &mut Window, cx: &mut App);
fn set_masked(&self, masked: bool, window: &mut Window, cx: &mut App);
fn set_read_only(&self, read_only: bool, cx: &mut App);
fn set_multiline(&self, max_lines: Option<usize>, window: &mut Window, cx: &mut App);
fn focus_handle(&self, cx: &App) -> FocusHandle;
fn subscribe(
&self,
callback: Box<dyn FnMut(ErasedEditorEvent, &mut Window, &mut App) + 'static>,
window: &mut Window,
cx: &mut App,
) -> Subscription;
fn render(&self, window: &mut Window, cx: &App) -> AnyElement;
fn as_any(&self) -> &dyn Any;
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ErasedEditorEvent {
BufferEdited,
Blurred,
}
pub static ERASED_EDITOR_FACTORY: OnceLock<fn(&mut Window, &mut App) -> Arc<dyn ErasedEditor>> =
OnceLock::new();