improve page search functionality to close with Escape key even when unfocused

This commit is contained in:
AJ Richardson
2026-10-19 16:37:52 +10:00
parent caf0f44d90
commit 3b7b28c03c
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -352,7 +352,7 @@ fn page_search_field(app: &mut FigApp, ui: &mut Ui, t: &Tokens, w: f32, id: Id,
if r.has_focus() {
ui.painter().rect_stroke(field, CornerRadius::same(5), Stroke::new(1.0, t.accent), egui::StrokeKind::Inside);
}
if (r.has_focus() || r.lost_focus()) && ui.input(|i| i.key_pressed(egui::Key::Escape)) {
if app.ui.page_search && ui.input(|i| i.key_pressed(egui::Key::Escape)) {
app.ui.page_search = false;
app.ui.page_filter.clear();
}
@@ -216,6 +216,19 @@ fn pages_search_button_opens_the_filter_and_escape_clears_it() {
assert!(u.app.ui.page_filter.is_empty(), "Escape clears the filter");
}
#[test]
fn pages_search_escape_closes_even_when_the_field_is_unfocused() {
let mut u = Ui::new(Session::new());
u.app.ui.page_search = true;
u.app.ui.page_filter = "COMPON".into();
u.frame(vec![]);
u.frame(vec![Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }]);
assert!(!u.app.ui.page_search, "Escape closes page search without field focus");
assert!(u.app.ui.page_filter.is_empty(), "Escape clears the filter without field focus");
}
#[test]
fn pages_search_filters_page_names_case_insensitively() {
let mut s = Session::new();