Components / display
HighlightedText builder
A run of text with some of it marked.
A builder is RenderOnce. Construct and mount it in one expression.
use gpui_kit::display::highlight::HighlightedText;
Reviewed in search-field.
Construct
new(text: impl Into<SharedString>) -> Self
Options
Chain onto the value.
id(ident: impl Into<Ident>) -> Self
selectable(ident: impl Into<Ident>) -> Self
in_document(order: u64, virtualized: bool) -> Self
hits(hits: impl IntoIterator<Item = Range<usize>>) -> Self
current(index: usize) -> Self
monospace(monospace: bool) -> Self
Queries
Only answer; they change nothing.
published_hits() -> usize
Example · search-field
fn search_field(window: &mut Window, cx: &mut App) -> AnyElement {
ensure_search(window, cx);
let field = cx.global::<SceneSearch>().field.clone();
let theme = cx.theme().clone();
let counting = cx.global::<SceneSearch>().counting.clone();
let none = cx.global::<SceneSearch>().none.clone();
let too_many = cx.global::<SceneSearch>().too_many.clone();
// The three counts a field must keep apart. No pointer position produces
// them at once, so each is stated.
stack(&theme)
.w(px(620.0))
.child(field)
.child(caption(
&theme,
"counting is not none, and too many is not a total",
))
.child(counting)
.child(none)
.child(too_many)
.child(caption(&theme, "the current hit is not the other hits"))
.child(
div().child(
HighlightedText::new(
"The transport reports what it did; the transport never decides.",
)
.id("scene.search.line")
.hits([4..13, 39..48])
.current(1),
),
)
.into_any_element()
}