Skip to main content

markdown/paint/
find.rs

1//! The washes behind transient find matches.
2
3use gpui::{App, Global, Hsla};
4use theme::Theme;
5
6/// Returns `(match, current)` washes for the theme. Keep the current match
7/// visibly stronger in both appearances.
8pub type FindPaint = fn(theme: &Theme) -> (Hsla, Hsla);
9
10struct Installed(FindPaint);
11
12impl Global for Installed {}
13
14/// Installs the find washes for editors and previews. Without it they use
15/// [`default_find`]. Call again to replace the paint when preferences change.
16pub(crate) fn set_find_paint(cx: &mut App, paint: FindPaint) {
17    cx.set_global(Installed(paint));
18}
19
20/// `(match, current)` washes cut from `color`: 22% for matches and 48% for
21/// the current match.
22pub fn find_washes(color: Hsla) -> (Hsla, Hsla) {
23    (color.opacity(0.22), color.opacity(0.48))
24}
25
26/// [`find_washes`] of the theme's accent.
27pub fn default_find(theme: &Theme) -> (Hsla, Hsla) {
28    find_washes(theme.accent)
29}
30
31pub(crate) fn find_paint_of(cx: &App) -> FindPaint {
32    cx.try_global::<Installed>()
33        .map_or(default_find, |installed| installed.0)
34}