Skip to main content

gpui_material_components/input/exposed_dropdown/
render.rs

1use std::{
2    cell::{Cell, RefCell},
3    rc::Rc,
4};
5
6use crate::{
7    MenuSurfaceStyle,
8    motion::{OverlayMotion, ScaledOverlay, menu_pivot},
9};
10use gpui::{
11    AccessibleAction, Anchor, AnyElement, App, Bounds, ElementId, Entity, EntityInputHandler,
12    FocusHandle, Focusable, Hsla, InteractiveElement, IntoElement, KeyDownEvent,
13    ListSizingBehavior, ListState, ParentElement, Pixels, RenderOnce, Role, SharedString,
14    StatefulInteractiveElement, Styled, Window, canvas, div, list, prelude::FluentBuilder, px,
15};
16use gpui_base::{Popup, TestSupportExt};
17use gpui_material_foundation::{
18    ThemeScope, animate, color, current_material_theme, logical_anchor,
19};
20use gpui_material_theme::{
21    ColorRole, Direction, MaterialTheme, MotionKind, MotionSpeed, TypeRole, TypographyEmphasis,
22};
23
24use super::{
25    super::{TextField, TextFieldVariant},
26    AnchorContent, DropdownAnchor, DropdownOption, ExposedDropdown, OpenChange, OptionContent,
27    Select,
28    state::{ExposedDropdownState, Opening, Visibility},
29};
30
31fn choose(
32    state: &Entity<ExposedDropdownState>,
33    choice: &DropdownOption,
34    callback: &Option<Select>,
35    window: &mut Window,
36    cx: &mut App,
37) {
38    state.update(cx, |state, cx| {
39        state.committed = choice.label.clone();
40        state.selected = Some(choice.id.clone());
41        state.reset_draft(window, cx);
42        state.request_open(false, None, window, cx);
43    });
44    if let Some(callback) = callback {
45        callback(choice, window, cx);
46    }
47}
48
49#[derive(Clone)]
50struct Interaction {
51    state: Entity<ExposedDropdownState>,
52    // The mounted handlers own the policy. The editor subscription observes it weakly.
53    _visibility: Rc<Visibility>,
54    select: Option<Select>,
55    primary: Opening,
56    primary_enabled: bool,
57    editable: bool,
58    parent: gpui::EntityId,
59}
60
61impl Interaction {
62    fn request(&self, open: Option<bool>, opening: Opening, window: &mut Window, cx: &mut App) {
63        self.state.update(cx, |state, cx| {
64            let open = open.unwrap_or(!state.open);
65            if open && matches!(opening, Opening::Editor) {
66                state.input.read(cx).focus_handle(cx).focus(window, cx);
67            }
68            state.request_open(open, open.then_some(opening), window, cx);
69        });
70        cx.notify(self.parent);
71    }
72
73    fn dismiss(&self, window: &mut Window, cx: &mut App) {
74        self.request(Some(false), self.primary, window, cx);
75    }
76
77    fn dismiss_outside(&self, window: &mut Window, cx: &mut App) {
78        let editor_focused = self
79            .state
80            .read(cx)
81            .input
82            .read(cx)
83            .focus_handle(cx)
84            .is_focused(window);
85        if editor_focused {
86            window.blur(cx);
87        }
88        self.dismiss(window, cx);
89    }
90
91    fn keys(&self, event: &KeyDownEvent, window: &mut Window, cx: &mut App) {
92        let key = event.keystroke.key.as_str();
93        if event.keystroke.modifiers.modified()
94            || !(matches!(key, "up" | "down" | "enter" | "escape")
95                || key == "space" && !self.editable)
96        {
97            return;
98        }
99        let model = self.state.read(cx);
100        let open = model.open;
101        let input = model.input.clone();
102        if !open && !self.primary_enabled
103            || input.update(cx, |input, cx| {
104                input.marked_text_range(window, cx).is_some()
105            })
106        {
107            return;
108        }
109        match key {
110            "up" | "down" => self.state.update(cx, |state, cx| {
111                state.navigate(key == "up", cx);
112                if state.open {
113                    return;
114                }
115                state.request_open(true, Some(self.primary), window, cx);
116            }),
117            "escape" if open => self.dismiss(window, cx),
118            "enter" if open => {
119                if let Some(choice) = self.state.read(cx).pending() {
120                    choose(&self.state, &choice, &self.select, window, cx);
121                }
122            }
123            "enter" | "space" if !self.editable => self.request(None, self.primary, window, cx),
124            _ => return,
125        }
126        cx.notify(self.parent);
127        cx.stop_propagation();
128    }
129}
130
131#[allow(clippy::too_many_arguments)]
132fn build_secondary_trigger(
133    secondary: Option<(SharedString, AnchorContent)>,
134    secondary_enabled: bool,
135    secondary_focus: &FocusHandle,
136    open: bool,
137    editable: bool,
138    primary: Opening,
139    arrow: f32,
140    ink: Hsla,
141    interaction: Interaction,
142) -> AnyElement {
143    let (secondary_label, secondary_content) = secondary.map_or_else(
144        || {
145            let label = if open {
146                "Close options"
147            } else {
148                "Open options"
149            };
150            (
151                SharedString::from(label),
152                dropdown_arrow(arrow, ink).into_any_element(),
153            )
154        },
155        |(label, content)| (label, content(open)),
156    );
157    if secondary_enabled {
158        let pointer = interaction.clone();
159        let a11y = interaction.clone();
160        let expansion = interaction;
161        let accessible_opening = if editable {
162            Opening::PopupFromSecondary
163        } else {
164            primary
165        };
166        gpui_base::Button::new("toggle-options")
167            .track_focus(secondary_focus)
168            .accessibility_label(secondary_label)
169            .aria_expanded(open)
170            .min_w(px(36.))
171            .min_h(px(36.))
172            .focus_visible(move |style| style.border_1().border_color(ink))
173            .on_click(move |_, window, cx| {
174                cx.stop_propagation();
175                pointer.request(None, primary, window, cx);
176            })
177            .on_a11y_action(AccessibleAction::Click, move |_, window, cx| {
178                a11y.request(None, accessible_opening, window, cx);
179            })
180            .on_a11y_action(
181                if open {
182                    AccessibleAction::Collapse
183                } else {
184                    AccessibleAction::Expand
185                },
186                move |_, window, cx| {
187                    expansion.request(Some(!open), accessible_opening, window, cx);
188                },
189            )
190            .child(secondary_content)
191            .into_any_element()
192    } else {
193        div()
194            .id("toggle-options-disabled")
195            .role(Role::Group)
196            .a11y_synthetic_children(|tree| tree.parent_node().set_hidden())
197            .min_w(px(36.))
198            .min_h(px(36.))
199            .flex()
200            .items_center()
201            .justify_center()
202            .opacity(0.38)
203            .child(secondary_content)
204            .into_any_element()
205    }
206}
207
208struct PopupGeometry {
209    anchor: Anchor,
210    height: Pixels,
211    width: Pixels,
212    gap: Pixels,
213}
214
215fn resolve_popup_geometry(
216    measured: Bounds<Pixels>,
217    viewport: gpui::Size<Pixels>,
218    direction: Direction,
219    match_anchor_width: bool,
220    popup_width: Pixels,
221) -> PopupGeometry {
222    let default_height = (viewport.height * 0.55).min(px(280.));
223    let gap = px(4.);
224    let margin = px(8.);
225    let (anchor, height) = if measured.size.height > px(0.) {
226        let below = (viewport.height - measured.bottom() - gap - margin).max(px(0.));
227        let above = (measured.top() - gap - margin).max(px(0.));
228        if below < default_height && above > below {
229            (Anchor::BottomLeft, default_height.min(above))
230        } else {
231            (Anchor::TopLeft, default_height.min(below))
232        }
233    } else {
234        (Anchor::TopLeft, default_height)
235    };
236    let anchor = logical_anchor(anchor, direction);
237    let width = if match_anchor_width {
238        if measured.size.width > px(0.) {
239            measured.size.width
240        } else {
241            px(120.)
242        }
243    } else {
244        popup_width
245    };
246    let width = width.min((viewport.width - margin * 2.).max(px(0.)));
247    PopupGeometry {
248        anchor,
249        height,
250        width,
251        gap,
252    }
253}
254
255struct OptionRowContext {
256    state: Entity<ExposedDropdownState>,
257    on_select: Option<Select>,
258    option_content: Option<OptionContent>,
259    open: bool,
260    parent: gpui::EntityId,
261    ink: Hsla,
262    selected_bg: Hsla,
263    selected_ink: Hsla,
264    min_height: Pixels,
265    horizontal_padding: Pixels,
266}
267
268fn render_option_row(
269    choice: DropdownOption,
270    index: usize,
271    total: usize,
272    current: bool,
273    ctx: &OptionRowContext,
274    window: &mut Window,
275    cx: &mut App,
276) -> AnyElement {
277    let content = ctx.option_content.as_ref().map_or_else(
278        || choice.label.clone().into_any_element(),
279        |content| content(&choice, current, window, cx),
280    );
281    let ink = ctx.ink;
282    let selected = ctx.selected_bg;
283    let selected_ink = ctx.selected_ink;
284    div()
285        .id(choice.id.clone())
286        .test_support()
287        .when(ctx.open, |row| {
288            row.role(Role::ListBoxOption)
289                .aria_label(choice.label.clone())
290                .aria_selected(current)
291                .aria_position_in_set(index + 1)
292                .aria_size_of_set(total)
293        })
294        .when(current, |row| row.bg(selected).text_color(selected_ink))
295        .when(ctx.open && current, |row| row.aria_active_descendant())
296        .when(ctx.open, |row| {
297            row.hover(move |style| {
298                style.bg(if current {
299                    selected.blend(selected_ink.opacity(0.08))
300                } else {
301                    ink.opacity(0.08)
302                })
303            })
304        })
305        .min_h(ctx.min_height)
306        .w_full()
307        .px(ctx.horizontal_padding)
308        .flex()
309        .items_center()
310        .child(content)
311        .when(ctx.open, |row| {
312            let state = ctx.state.clone();
313            let callback = ctx.on_select.clone();
314            let parent = ctx.parent;
315            let select_row = Rc::new(move |window: &mut Window, cx: &mut App| {
316                choose(&state, &choice, &callback, window, cx);
317                cx.notify(parent);
318            });
319            let accessible_select = select_row.clone();
320            row.on_a11y_action(AccessibleAction::Click, move |_, window, cx| {
321                accessible_select(window, cx);
322            })
323            .on_click(move |_, window, cx| {
324                select_row(window, cx);
325            })
326        })
327        .into_any_element()
328}
329
330struct PopupContentConfig {
331    state: Entity<ExposedDropdownState>,
332    scroll: ListState,
333    open: bool,
334    options: Rc<[DropdownOption]>,
335    active: Option<ElementId>,
336    selected_option: Option<ElementId>,
337    options_label: String,
338    transfer_focus: bool,
339    popup_focus: FocusHandle,
340    popup_keys: Interaction,
341    outside: Interaction,
342    bounds: Rc<Cell<Bounds<Pixels>>>,
343    placement: Rc<Cell<(Bounds<Pixels>, Bounds<Pixels>)>>,
344    last_trigger: Bounds<Pixels>,
345    width: Pixels,
346    height: Pixels,
347    appearance: MenuSurfaceStyle,
348    container_color: Option<Hsla>,
349    on_select: Option<Select>,
350    option_content: Option<OptionContent>,
351    parent: gpui::EntityId,
352    theme: MaterialTheme,
353    ink: Hsla,
354    selected_bg: Hsla,
355    selected_ink: Hsla,
356}
357
358fn build_popup_content(
359    config: PopupContentConfig,
360    motion: OverlayMotion,
361    window: &mut Window,
362    cx: &mut App,
363) -> AnyElement {
364    let dp = move |value| motion.px(value);
365    let spacing = dp(16.);
366    let scroll_height =
367        (config.height - config.appearance.popup_vertical_insets()).max(px(0.)) * motion.scale;
368    let font_revision = gpui_material_foundation::font_cache_revision(cx);
369    config.state.update(cx, |state, _| {
370        state.sync_presented_list(
371            &config.options,
372            config.active.as_ref(),
373            (
374                config.width,
375                motion.scale,
376                window.rem_size(),
377                config.theme.typography.clone(),
378                font_revision,
379            ),
380        );
381    });
382    let options = config.options;
383    let active = config.active;
384    let selected_option = config.selected_option;
385    let open = config.open;
386    let list_body = if options.is_empty() {
387        div()
388            .id("options-scroll-region")
389            .test_support()
390            .max_h(scroll_height)
391            .overflow_hidden()
392            .child(
393                div()
394                    .px(spacing * 0.75)
395                    .py(spacing * 0.5)
396                    .child("No matching options"),
397            )
398            .into_any_element()
399    } else {
400        let row_ctx = Rc::new(OptionRowContext {
401            state: config.state,
402            on_select: config.on_select,
403            option_content: config.option_content,
404            open,
405            parent: config.parent,
406            ink: config.ink,
407            selected_bg: config.selected_bg,
408            selected_ink: config.selected_ink,
409            min_height: dp(48.),
410            horizontal_padding: spacing * 0.75,
411        });
412        div()
413            .id("options-scroll-region")
414            .test_support()
415            .max_h(scroll_height)
416            .overflow_hidden()
417            .child(
418                list(config.scroll, move |index, window, cx| {
419                    let choice = options[index].clone();
420                    let current = active.as_ref().or(selected_option.as_ref()) == Some(&choice.id);
421                    render_option_row(choice, index, options.len(), current, &row_ctx, window, cx)
422                })
423                .with_sizing_behavior(ListSizingBehavior::Infer)
424                .w_full()
425                .max_h(scroll_height),
426            )
427            .into_any_element()
428    };
429    let bounds = config.bounds;
430    let popup_focus = config.popup_focus;
431    let popup_keys = config.popup_keys;
432    let outside = config.outside;
433    let content = div()
434        .id(if open { "options" } else { "options-exit" })
435        .test_support()
436        .opacity(motion.alpha)
437        .w(config.width * motion.scale)
438        .text_color(config.ink)
439        .max_h(config.height * motion.scale)
440        .when(open, |list| {
441            list.role(Role::ListBox)
442                .aria_label(config.options_label)
443                .when(config.transfer_focus, |list| {
444                    list.track_focus(&popup_focus).tab_stop(false)
445                })
446                .capture_key_down(move |event, window, cx| popup_keys.keys(event, window, cx))
447                .on_mouse_down_out(move |event, window, cx| {
448                    if !bounds.get().contains(&event.position) {
449                        outside.dismiss_outside(window, cx);
450                    }
451                })
452        })
453        .child(
454            config
455                .appearance
456                .dropdown_surface(&config.theme, motion)
457                .when_some(config.container_color, |surface, color| surface.bg(color))
458                .w_full()
459                .child(list_body),
460        )
461        .when(!open, |list| {
462            list.child(div().absolute().inset_0().occlude())
463        });
464    let text_style = TypeRole::LabelLarge.style(TypographyEmphasis::Baseline);
465    let content =
466        gpui_material_foundation::text_style(content, text_style, motion.scale, window, cx);
467    let placement = config.placement;
468    let last_trigger = config.last_trigger;
469    let scaled = ScaledOverlay::new(content, motion, move |menu| {
470        menu_pivot(
471            menu,
472            if open {
473                placement.get().1
474            } else {
475                last_trigger
476            },
477        )
478    })
479    .width(config.width);
480    ThemeScope::inherit(scaled, window, cx)
481}
482
483impl RenderOnce for ExposedDropdown {
484    fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
485        let primary = if self.primary == Some(DropdownAnchor::PrimaryNotEditable) {
486            Opening::PopupFromPrimary
487        } else {
488            Opening::Editor
489        };
490        let visibility = Rc::new(self.visibility);
491        let (
492            input,
493            open,
494            editable,
495            popup_focus,
496            transfer_focus,
497            secondary_focus,
498            scroll,
499            options,
500            active,
501            selected_option,
502        ) = self.state.update(cx, |state, cx| {
503            state.present(
504                &visibility,
505                self.primary_enabled,
506                self.secondary_enabled,
507                primary,
508                window,
509                cx,
510            );
511            let input = state.input.clone();
512            let open = state.open;
513            let editable = state.editable;
514            let popup_focus = state.popup_focus.clone();
515            let transfer_focus = state.restore_focus.is_some();
516            let secondary_focus = state.secondary_focus.clone();
517            let scroll = state.scroll.clone();
518            let (query, composing) = input.update(cx, |input, cx| {
519                (
520                    input.value(),
521                    editable && input.marked_text_range(window, cx).is_some(),
522                )
523            });
524            let filter = editable && !composing && query != state.committed;
525            let (options, active, selected_option) =
526                state.reconcile_options(&self.options, filter.then_some(query));
527            (
528                input,
529                open,
530                editable,
531                popup_focus,
532                transfer_focus,
533                secondary_focus,
534                scroll,
535                options,
536                active,
537                selected_option,
538            )
539        });
540        let last_visible_options = window
541            .use_keyed_state((self.id.clone(), "presented-options"), cx, |_, _| {
542                Rc::new(RefCell::new((
543                    Rc::<[DropdownOption]>::default(),
544                    None::<ElementId>,
545                    None::<ElementId>,
546                )))
547            })
548            .read(cx)
549            .clone();
550        if open {
551            let mut visible = last_visible_options.borrow_mut();
552            visible.0 = options.clone();
553            visible.1.clone_from(&active);
554            visible.2.clone_from(&selected_option);
555        }
556        let theme = current_material_theme(window, cx);
557        let ink = color(theme.colors.color(ColorRole::OnSurface));
558        let selected_bg = color(theme.colors.color(ColorRole::SecondaryContainer));
559        let selected_ink = color(theme.colors.color(ColorRole::OnSecondaryContainer));
560        let arrow = animate(
561            (self.id.clone(), "arrow"),
562            f32::from(open),
563            theme
564                .motion
565                .spec(MotionKind::Effects, MotionSpeed::Fast, cx.reduce_motion()),
566            window,
567            cx,
568        )
569        .clamp(0., 1.);
570        let parent = window.current_view();
571        let interaction = Interaction {
572            state: self.state.clone(),
573            _visibility: visibility,
574            select: self.on_select.clone(),
575            primary,
576            primary_enabled: self.primary_enabled,
577            editable,
578            parent,
579        };
580        let popup_keys = interaction.clone();
581        let outside = interaction.clone();
582        let keys = interaction.clone();
583        let primary_click = interaction.clone();
584        let request: Option<OpenChange> = self.primary_enabled.then(|| {
585            let interaction = interaction.clone();
586            Rc::new(move |open, window: &mut Window, cx: &mut App| {
587                interaction.request(Some(open), primary, window, cx);
588            }) as OpenChange
589        });
590        let secondary = build_secondary_trigger(
591            self.secondary,
592            self.secondary_enabled,
593            &secondary_focus,
594            open,
595            editable,
596            primary,
597            arrow,
598            ink,
599            interaction,
600        );
601        let options_label = format!("{} options", self.label);
602        let field = TextField::new("value", self.label, &input)
603            .variant(TextFieldVariant::Outlined)
604            .dropdown(open, request)
605            .trailing(secondary);
606        let editor = if let Some(editor) = self.editor {
607            editor(field)
608        } else {
609            field.into_any_element()
610        };
611
612        let bounds = window
613            .use_keyed_state((self.id.clone(), "bounds"), cx, |_, _| {
614                Rc::new(Cell::new(Bounds::default()))
615            })
616            .read(cx)
617            .clone();
618        let measure = bounds.clone();
619        let geometry = resolve_popup_geometry(
620            bounds.get(),
621            window.viewport_size(),
622            theme.layout.direction,
623            self.match_anchor_width,
624            self.popup_width,
625        );
626        let trigger = div()
627            .id((self.id.clone(), "combobox"))
628            .test_support()
629            .when(
630                self.primary_enabled && (!editable || self.primary.is_some()),
631                |trigger| {
632                    trigger.on_click(move |_, window, cx| {
633                        primary_click.request(None, primary, window, cx);
634                    })
635                },
636            )
637            // TextField owns the single combo box node and delegates IME to its editor.
638            .capture_key_down(move |event, window, cx| keys.keys(event, window, cx))
639            .child(editor)
640            .relative()
641            .child(
642                canvas(
643                    move |bounds, window, _| {
644                        if measure.replace(bounds) != bounds && open {
645                            window.refresh();
646                        }
647                    },
648                    |_, _, _, _| {},
649                )
650                .absolute()
651                .inset_0(),
652            )
653            // Keep the default cursor over the read-only editor's I-beam.
654            .when(!editable, |trigger| {
655                trigger.child(div().absolute().inset_0().cursor_default())
656            });
657        let motion = OverlayMotion::sample(&self.id, open, window, cx);
658        let placement = window
659            .use_keyed_state((self.id.clone(), "last-popup-bounds"), cx, |_, _| {
660                Rc::new(Cell::new((Bounds::default(), Bounds::default())))
661            })
662            .read(cx)
663            .clone();
664        let (last_bounds, last_trigger) = placement.get();
665        let trigger_bounds = placement.clone();
666        let popup = Popup::new(self.id.clone(), trigger)
667            .anchor(geometry.anchor)
668            .offset(geometry.gap)
669            .on_position(move |resolved, trigger| trigger_bounds.set((resolved.bounds, trigger)));
670        let content = motion.map(|motion| {
671            let (options, active, selected_option) = if open {
672                (options, active, selected_option)
673            } else {
674                last_visible_options.borrow().clone()
675            };
676            let width = if open {
677                geometry.width
678            } else {
679                last_bounds.size.width
680            };
681            build_popup_content(
682                PopupContentConfig {
683                    state: self.state,
684                    scroll,
685                    open,
686                    options,
687                    active,
688                    selected_option,
689                    options_label,
690                    transfer_focus,
691                    popup_focus,
692                    popup_keys,
693                    outside,
694                    bounds,
695                    placement,
696                    last_trigger,
697                    width,
698                    height: geometry.height,
699                    appearance: self.appearance,
700                    container_color: self.container_color,
701                    on_select: self.on_select,
702                    option_content: self.option_content,
703                    parent,
704                    theme: (*theme).clone(),
705                    ink,
706                    selected_bg,
707                    selected_ink,
708                },
709                motion,
710                window,
711                cx,
712            )
713        });
714        if open {
715            return div().child(popup.content(content.expect("open dropdown")));
716        }
717        let exit = content
718            .filter(|_| last_bounds.size.width > px(0.))
719            .map(|content| {
720                gpui::deferred(
721                    gpui_base::Positioner::corner(Anchor::TopLeft, last_bounds.origin)
722                        .child(content),
723                )
724                .with_priority(100)
725            });
726        div().child(popup).children(exit)
727    }
728}
729
730// The official dropdown symbol rotates with the existing expansion animation.
731// Keep this decorative element separate from the Base trigger's semantics.
732fn dropdown_arrow(progress: f32, ink: Hsla) -> impl IntoElement {
733    div()
734        .flex()
735        .items_center()
736        .justify_center()
737        .text_color(ink)
738        .child(
739            crate::Icon::new(crate::IconName::ArrowDropDown)
740                .size(px(24.))
741                .rotate(gpui::radians(std::f32::consts::PI * progress)),
742        )
743}
744
745#[cfg(test)]
746mod tests {
747    use super::super::state::{OptionSnapshot, contains_ignore_case};
748    use super::*;
749
750    #[test]
751    fn option_snapshot_reuses_results_and_invalidates_labels_and_query() {
752        let mut snapshot = OptionSnapshot::default();
753        let options = || -> Rc<[DropdownOption]> {
754            vec![
755                DropdownOption::new("a", "Alpha"),
756                DropdownOption::new("b", "Beta"),
757            ]
758            .into()
759        };
760        let shared = options();
761        assert!(snapshot.reconcile(&shared, None));
762        let unfiltered = snapshot.visible.clone();
763        assert!(Rc::ptr_eq(&unfiltered, &snapshot.source));
764        assert!(Rc::ptr_eq(&unfiltered, &shared));
765        assert!(!snapshot.reconcile(&shared, None));
766        assert!(Rc::ptr_eq(&unfiltered, &snapshot.visible));
767        let cloned_equal = options();
768        assert!(!snapshot.reconcile(&cloned_equal, None));
769        assert!(Rc::ptr_eq(&snapshot.source, &cloned_equal));
770        assert!(Rc::ptr_eq(&unfiltered, &snapshot.visible));
771        assert!(snapshot.reconcile(&shared, Some("ALP".into())));
772        assert_eq!(snapshot.visible.len(), 1);
773        assert_eq!(snapshot.visible[0].id, ElementId::from("a"));
774        let renamed: Rc<[DropdownOption]> = vec![
775            DropdownOption::new("a", "Renamed"),
776            DropdownOption::new("b", "Beta"),
777        ]
778        .into();
779        assert!(snapshot.reconcile(&renamed, Some("ALP".into())));
780        assert!(snapshot.visible.is_empty());
781    }
782
783    #[test]
784    fn contains_ignore_case_handles_ascii_and_unicode() {
785        assert!(contains_ignore_case("Alpha Beta", "", ""));
786        assert!(contains_ignore_case("Alpha Beta", "ALP", "alp"));
787        assert!(contains_ignore_case("Alpha Beta", "beta", "beta"));
788        assert!(!contains_ignore_case("Alpha", "Alpha Beta", "alpha beta"));
789        assert!(contains_ignore_case("北京市", "北京", "北京"));
790        assert!(contains_ignore_case("Café Crème", "CAFÉ", "café"));
791    }
792}