From 03e36ab0effda9b08d5355aff95b071fefd9ad13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Sat, 26 Sep 2026 12:44:18 -0400 Subject: [PATCH] Generative: a picture with nothing to open takes no focus A done result tracks its focus only beside its press, so a grid with no open handler leaves focus where it was. A decided comparison drops its empty verdict row, so no gap is left under the sides. --- TASKS.md | 1 + src/generative/compare.rs | 22 ++++++++++++---------- src/generative/grid.rs | 4 ++-- src/generative/tests/results.rs | 32 +++++++++++++++++++++++++++++++- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/TASKS.md b/TASKS.md index 8a6cc98..c73326f 100644 --- a/TASKS.md +++ b/TASKS.md @@ -293,3 +293,4 @@ Per-component lines live in `tasks/`. Tags there: | T24f | 2 | PASS | | | T25a | 1 | FAIL | Cmd-Enter generated only while a text field held focus; the form set no key context of its own | | T25a | 2 | PASS | | +| T25b | 1 | FAIL | a done result with nothing to open still took focus on a press and drew a ring the keys could not reach | diff --git a/src/generative/compare.rs b/src/generative/compare.rs index a42b96c..dd2458a 100644 --- a/src/generative/compare.rs +++ b/src/generative/compare.rs @@ -173,16 +173,18 @@ impl RenderOnce for ABCompareView { .flex_col() .gap_3() .child(div().w_full().flex().flex_wrap().gap_3().children(sides)) - .child( - div() - .flex() - .flex_wrap() - .items_center() - .gap_2() - .text_size(theme.text_size(TextSize::Sm)) - .text_color(colors.fg_muted) - .children(verdicts), - ) + .when(!verdicts.is_empty(), |column| { + column.child( + div() + .flex() + .flex_wrap() + .items_center() + .gap_2() + .text_size(theme.text_size(TextSize::Sm)) + .text_color(colors.fg_muted) + .children(verdicts), + ) + }) } } diff --git a/src/generative/grid.rs b/src/generative/grid.rs index 7752998..9e71de7 100644 --- a/src/generative/grid.rs +++ b/src/generative/grid.rs @@ -128,9 +128,9 @@ impl RenderOnce for GenerationGrid { Outcome::Done(picture) => { let open = self.on_open.clone(); frame - .track_focus(&focus) .when_some(open, |tile, open| { - tile.cursor_pointer() + tile.track_focus(&focus) + .cursor_pointer() .on_mouse_down(MouseButton::Left, |_, window, _| { window.prevent_default() }) diff --git a/src/generative/tests/results.rs b/src/generative/tests/results.rs index 889ee25..49d3c86 100644 --- a/src/generative/tests/results.rs +++ b/src/generative/tests/results.rs @@ -1,6 +1,9 @@ use std::{cell::RefCell, rc::Rc, time::Duration}; -use gpui::{Context, IntoElement, ParentElement, Render, Styled, TestAppContext, Window, div, px}; +use gpui::{ + Context, IntoElement, Modifiers, ParentElement, Render, Styled, TestAppContext, Window, div, + point, px, +}; use super::{press, settle, setup, tab}; use crate::generative::{ @@ -94,6 +97,33 @@ fn only_done_results_open_and_a_failure_retries(cx: &mut TestAppContext) { ); } +/// A single picture with nothing to open it. +struct Still; + +impl Render for Still { + fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { + div().w(px(420.0)).child(GenerationGrid::new( + "still", + [Outcome::Done("missing.jpg".into())], + 1.5, + )) + } +} + +#[gpui::test] +fn a_picture_with_nothing_to_open_takes_no_focus(cx: &mut TestAppContext) { + setup(cx); + let (_, cx) = cx.add_window_view(|_, _| Still); + cx.update(|window, _| window.activate_window()); + settle(cx); + cx.simulate_click(point(px(100.0), px(60.0)), Modifiers::none()); + settle(cx); + assert!( + cx.update(|window, cx| window.focused(cx).is_none()), + "no ring on a picture the keys cannot use" + ); +} + /// Three variations with the first chosen, and what it heard. struct Variations(Heard);