From a32fe7d6fda3bbb6e08acd0b442b5cd448a24d2f Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 21 Nov 2026 01:50:30 +0000 Subject: [PATCH 1/2] Option lists: hover moves only the lead HoverLead (Off, Lead, LeadAndSelection) replaces lead_follows_hover. List::options takes Lead, so the hovered row no longer draws as the chosen option for a frame; UndoList keeps LeadAndSelection. --- crates/ui-contract/src/contract/collection.rs | 3 +- .../src/contract/collection/props.rs | 28 ++++++++++++++----- .../ui-contract/src/contract/items/hooks.rs | 6 ++-- crates/ui-contract/src/contract/items/lead.rs | 12 ++++---- crates/ui-contract/src/contract/mod.rs | 4 +-- crates/ui-macros/src/props.rs | 2 +- crates/ui-widgets/src/list/undo.rs | 6 ++-- crates/ui-widgets/src/list/view.rs | 4 +-- .../tests/it/pickers/select_list.rs | 24 ++++++++++++++++ 9 files changed, 65 insertions(+), 24 deletions(-) diff --git a/crates/ui-contract/src/contract/collection.rs b/crates/ui-contract/src/contract/collection.rs index 754053cdc6..623ac6612d 100644 --- a/crates/ui-contract/src/contract/collection.rs +++ b/crates/ui-contract/src/contract/collection.rs @@ -12,7 +12,8 @@ pub use events::{ CollectionEvent, ColumnEvent, ColumnRequest, ContextMenuRequest, HeaderMenuRequest, ListDrag, OpenChange, Rename, ReorderMove, ToggleEdit, }; pub use props::{ - ActivateOn, CollectionProps, DragPayload, ItemKeys, LeadOnOpen, LeadSource, ReorderRule, RowHeight, RowPressed, RowState, SelectMode, SpaceAction, + ActivateOn, CollectionProps, DragPayload, HoverLead, ItemKeys, LeadOnOpen, LeadSource, ReorderRule, RowHeight, RowPressed, RowState, SelectMode, + SpaceAction, }; pub(crate) use response::Gestures; pub(crate) use response::ItemsOut; diff --git a/crates/ui-contract/src/contract/collection/props.rs b/crates/ui-contract/src/contract/collection/props.rs index 3c464e0b48..db45f0d04a 100644 --- a/crates/ui-contract/src/contract/collection/props.rs +++ b/crates/ui-contract/src/contract/collection/props.rs @@ -119,6 +119,21 @@ pub enum LeadOnOpen { First, } +/// What the pointer moving over the rows changes. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] +pub enum HoverLead { + /// Nothing: only a press moves the lead. + #[default] + Off, + /// The lead moves to the row under the pointer; the selection stays until a pick (click, Enter, or a key move): + /// option lists, where the selection is the chosen value. + Lead, + /// The lead moves and picks the row, as the arrow keys do: menus and the undo list, where the hover range is + /// the point. + LeadAndSelection, +} + /// How tall a collection's rows are. Read-only display tables (a metadata table) take text rows; lists the user picks /// from or navigates keep control-high rows, a pointer target as tall as a control. A row with a thumbnail or a /// detail line is as tall as those need either way. @@ -173,9 +188,8 @@ pub struct CollectionProps { pub allow_empty: bool, /// Where the lead starts. pub lead_on_open: LeadOnOpen, - /// The lead, and the selection with it as for the arrow keys, moves to the row under the pointer when the pointer - /// moves: menus, popup lists and the undo list. - pub lead_follows_hover: bool, + /// What the pointer moving over the rows changes: the lead, and for some lists the selection too. + pub hover_lead: HoverLead, /// The arrow keys select the row they move the lead to. Off: they move the lead only, and Space, Enter or a click /// selects it (a swatch table, a tab strip, a preset browser); Enter then activates it as well. pub arrows_select: bool, @@ -299,7 +313,7 @@ impl CollectionProps { striped: false, allow_empty: false, lead_on_open: LeadOnOpen::Selected, - lead_follows_hover: false, + hover_lead: HoverLead::Off, arrows_select: true, focus_on_press: true, rows_stamp: None, @@ -434,10 +448,10 @@ impl CollectionProps { self } - /// The lead follows the pointer over the rows. + /// What the pointer moving over the rows changes. #[must_use] - pub const fn lead_follows_hover(mut self, on: bool) -> Self { - self.lead_follows_hover = on; + pub const fn hover_lead(mut self, hover: HoverLead) -> Self { + self.hover_lead = hover; self } diff --git a/crates/ui-contract/src/contract/items/hooks.rs b/crates/ui-contract/src/contract/items/hooks.rs index a3b6225fdf..40671bf6f5 100644 --- a/crates/ui-contract/src/contract/items/hooks.rs +++ b/crates/ui-contract/src/contract/items/hooks.rs @@ -8,7 +8,7 @@ use super::{Held, ITEM_NODE, ItemsHooks, LastLayout, Lead, Placement, Renaming, use super::{request, rows}; use crate::contract::ValueOf; use crate::contract::collection::{ - CollectionEvent, ColumnLayout, ContextMenuRequest, DropAt, Gestures, ItemsOut, OpenChange, PendingDrop, Rename, RowState, ShownRow, + CollectionEvent, ColumnLayout, ContextMenuRequest, DropAt, Gestures, HoverLead, ItemsOut, OpenChange, PendingDrop, Rename, RowState, ShownRow, }; use crate::contract::cx::{BodyCx, CxCore, Pointer as _}; use crate::contract::run::{Measuring, ShapeHooks, ShowAt}; @@ -277,8 +277,8 @@ impl ShapeHooks for ItemsHooks<'_, '_, C> { let seen = Placement { offset: ScrollPos { x: self.offset_x_at_read, y: self.offset_at_read }, ..at }; self.edge_step(cx); self.press_step(comp, cx, &props, &layout, seen); - if props.lead_follows_hover { - self.hover_lead(comp, cx, &layout, seen); + if props.hover_lead != HoverLead::Off { + self.hover_lead(comp, cx, &layout, seen, props.hover_lead); } if props.select_under_drag { self.drag_select(comp, cx, &layout, seen); diff --git a/crates/ui-contract/src/contract/items/lead.rs b/crates/ui-contract/src/contract/items/lead.rs index 88e0698720..6d69fd2ea1 100644 --- a/crates/ui-contract/src/contract/items/lead.rs +++ b/crates/ui-contract/src/contract/items/lead.rs @@ -1,7 +1,7 @@ //! The lead and the selection: picks, ranges, and where the lead starts and follows. use super::{ItemsHooks, Placement}; -use crate::contract::collection::{CollectionEvent, LeadOnOpen, LeadSource, ListDrag, SelectMode}; +use crate::contract::collection::{CollectionEvent, HoverLead, LeadOnOpen, LeadSource, ListDrag, SelectMode}; use crate::contract::{Collection, Cx}; use craft_behavior::{Flow, ItemLayout, PointerEvent, SelectionChange, SelectionModel}; use egui::{Pos2, Rect, Vec2}; @@ -135,10 +135,10 @@ impl ItemsHooks<'_, '_, C> { layout.hit(local, offset).filter(|&row| self.source.enabled(row) && !self.source.is_section(row) && layout.shown(row)) } - /// The lead follows a moving pointer over the rows, and the selection follows the lead the way it does for the - /// arrow keys. A pass moves the pointer when it holds a move event: the pointer entering over a row moves the lead + /// The lead follows a moving pointer over the rows; with `HoverLead::LeadAndSelection` the selection follows the + /// lead the way it does for the arrow keys. A pass moves the pointer when it holds a move event: the pointer entering over a row moves the lead /// with no movement to measure, and a modifier change under a resting pointer leaves the lead where the keys put it. - pub(super) fn hover_lead(&mut self, comp: &C, cx: &Cx<'_, C>, layout: &C::ItemLayout, at: Placement) { + pub(super) fn hover_lead(&mut self, comp: &C, cx: &Cx<'_, C>, layout: &C::ItemLayout, at: Placement, hover: HoverLead) { let moved = crate::runtime::pointer::with_pass_raw(&cx.core.ctx, |pass| pass.events.iter().any(|event| matches!(event, PointerEvent::Moved { .. }))); if !moved { @@ -147,7 +147,9 @@ impl ItemsHooks<'_, '_, C> { let Some(row) = Self::hovered_pos(cx).and_then(|pos| self.row_under(layout, at, pos)) else { return }; if self.lead.key.as_ref() != Some(&self.source.key(row)) { self.move_lead(row, LeadSource::Pointer); - self.pick(comp, row, false, false); + if hover == HoverLead::LeadAndSelection { + self.pick(comp, row, false, false); + } } } diff --git a/crates/ui-contract/src/contract/mod.rs b/crates/ui-contract/src/contract/mod.rs index 14ea466f79..75f800d749 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -60,8 +60,8 @@ pub use body::{STRIP_BACK, STRIP_FORWARD}; pub use collection::{ ActivateOn, CollectionEvent, CollectionProps, CollectionResponse, ColumnAlign, ColumnEvent, ColumnKind, ColumnLayout, ColumnRemove, ColumnRequest, ColumnSort, ColumnSpec, ContextMenuRequest, DragPayload, DropAt, DropKind, DropPayload, DropPlace, EdgePress, HeaderMenuRequest, - ItemKeys, LeadOnOpen, LeadSource, ListDrag, OpenChange, PendingDrop, Rename, ReorderMove, ReorderRule, RowHeight, RowPressed, RowState, - SelectMode, ShownRow, SpaceAction, ToggleColumn, ToggleEdit, + HoverLead, ItemKeys, LeadOnOpen, LeadSource, ListDrag, OpenChange, PendingDrop, Rename, ReorderMove, ReorderRule, RowHeight, RowPressed, + RowState, SelectMode, ShownRow, SpaceAction, ToggleColumn, ToggleEdit, }; #[doc(hidden)] pub use container::InBar; diff --git a/crates/ui-macros/src/props.rs b/crates/ui-macros/src/props.rs index 158382be1d..e334f26f81 100644 --- a/crates/ui-macros/src/props.rs +++ b/crates/ui-macros/src/props.rs @@ -175,7 +175,7 @@ const COLLECTION: &[Forwarded] = &[ ("striped", "bool", "Odd rows are tinted: the item reads `ItemCx::row.striped`."), ("allow_empty", "bool", "A press on the empty space below the rows empties the selection."), ("lead_on_open", "$ui::contract::LeadOnOpen", "Where the lead lands when rows first show."), - ("lead_follows_hover", "bool", "The lead, and the selection with it, moves to the row under the pointer when the pointer moves."), + ("hover_lead", "$ui::contract::HoverLead", "What the pointer moving over the rows changes: nothing, the lead, or the lead and the selection."), ("arrows_select", "bool", "The arrow keys select the row they move the lead to; off, they move the lead only."), ("arrows_wrap", "bool", "The arrow keys wrap from the last item to the first and back."), ("type_ahead", "bool", "Typed letters move the lead to the next item whose text starts with them; off, they stay shortcut candidates."), diff --git a/crates/ui-widgets/src/list/undo.rs b/crates/ui-widgets/src/list/undo.rs index bd77b65e70..06277827e3 100644 --- a/crates/ui-widgets/src/list/undo.rs +++ b/crates/ui-widgets/src/list/undo.rs @@ -4,8 +4,8 @@ use super::view_words::UndoWords; use super::{ListRow, RowEvent}; use crate::contract::{ - ActivateOn, Bind, BindMut, Collection, CollectionEvent, CollectionProps, CollectionResponse, Common, Component, ContainerProps, Cx, Props as _, - Role, RowState, SelectMode, Sizing, + ActivateOn, Bind, BindMut, Collection, CollectionEvent, CollectionProps, CollectionResponse, Common, Component, ContainerProps, Cx, HoverLead, + Props as _, Role, RowState, SelectMode, Sizing, }; use crate::runtime::env::Label; use crate::style::{ComponentStyle, StyleCx}; @@ -141,7 +141,7 @@ impl<'a> UndoList<'a> { UndoList { common: Common::new(), props: ContainerProps::new().sizing(Sizing::Fill), - items: CollectionProps::new().select(SelectMode::Single).activate(ActivateOn::Click).lead_follows_hover(true), + items: CollectionProps::new().select(SelectMode::Single).activate(ActivateOn::Click).hover_lead(HoverLead::LeadAndSelection), selection: None, } .label(label) diff --git a/crates/ui-widgets/src/list/view.rs b/crates/ui-widgets/src/list/view.rs index b2a22580d7..541af3cb5a 100644 --- a/crates/ui-widgets/src/list/view.rs +++ b/crates/ui-widgets/src/list/view.rs @@ -7,7 +7,7 @@ use super::predicate::{DropTest, RowTest, RowText}; use super::{ListRow, RowEvent}; use crate::contract::{ Access, ActivateOn, Bind, BindMut, Collection, CollectionProps, CollectionResponse, ColumnLayout, Common, Component, ContainerProps, Cx, - DropKind, EdgePress, EditResponse, LeadOnOpen, ListDrag, Props as _, Role, RowState, SelectMode, Sizing, + DropKind, EdgePress, EditResponse, HoverLead, LeadOnOpen, ListDrag, Props as _, Role, RowState, SelectMode, Sizing, }; use crate::runtime::env::{Env, Label}; use crate::style::{ComponentStyle, StyleCx}; @@ -119,7 +119,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> List<'a, K> { .select(SelectMode::Single) .activate(ActivateOn::Click) .lead_on_open(LeadOnOpen::First) - .lead_follows_hover(true) + .hover_lead(HoverLead::Lead) .focus_on_press(false) .type_ahead(true) .sizing(Sizing::Content) diff --git a/crates/ui-widgets/tests/it/pickers/select_list.rs b/crates/ui-widgets/tests/it/pickers/select_list.rs index 801ccefeb8..4a129d72a0 100644 --- a/crates/ui-widgets/tests/it/pickers/select_list.rs +++ b/crates/ui-widgets/tests/it/pickers/select_list.rs @@ -297,3 +297,27 @@ fn the_wheel_steps_the_open_select_a_line_an_entry_and_commits_when_it_stops() { assert!(!steps.contains(&"cancel"), "and puts nothing back: {steps:?}"); assert_eq!(*value.borrow(), 4); } + +/// The pointer over a row of an open list moves the lead only: the held value stays the selected option in every +/// frame, and Enter then chooses the row the pointer is on. +#[trial] +fn hovering_a_row_moves_the_lead_and_leaves_the_selected_option_held() { + use craft_ui::testing::pointer::moved; + let mut fixture = focused(); + fixture.key(Key::ArrowDown, Modifiers::ALT); + fixture.settle(); + assert!(list_open(&mut fixture), "Alt+Down opens the list"); + let options = fixture.by_role(Role::LIST_BOX_OPTION); + assert_eq!(options.len(), 4, "the list shows its four options"); + let held = options[0].node; + let under_pointer = options[2].center(); + for step in 0..3 { + fixture.frame(if step == 0 { vec![moved(under_pointer)] } else { Vec::new() }); + let selected: Vec<_> = + fixture.by_role(Role::LIST_BOX_OPTION).into_iter().filter(|row| fixture.tree().selected_of(row.node) == Some(true)).collect(); + assert!(selected.len() == 1 && selected[0].node == held, "frame {step}: the held row stays the selected option"); + } + fixture.key(Key::Enter, Modifiers::NONE); + fixture.settle(); + assert_eq!(value(&mut fixture), 3, "the lead followed the pointer, so Enter chooses the row under it"); +} From af50339b27c9880e448ae9c9ce6202bcf07fc532 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 21 Nov 2026 01:52:27 +0000 Subject: [PATCH 2/2] Escape keeps the anchor selection under Direct, Convert and Curvature The overlay no longer clears the selection on Escape; the key goes on to the window as in 0.23.1. --- crates/draw/src/ui/pen/bezier/mod.rs | 5 +---- crates/draw/src/ui/pen/bezier/tools.rs | 2 +- crates/draw/tests/it/bezier.rs | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/draw/src/ui/pen/bezier/mod.rs b/crates/draw/src/ui/pen/bezier/mod.rs index fbca9ff8a4..2f428b0f3b 100644 --- a/crates/draw/src/ui/pen/bezier/mod.rs +++ b/crates/draw/src/ui/pen/bezier/mod.rs @@ -398,7 +398,7 @@ struct Scene { /// the selected anchors or the picked handle (⌥ alone); Delete and Backspace report /// [`delete`](BezierOutput::delete) under the tools that delete anchors (Direct, Convert, Curvature, Add Anchor, /// Delete Anchor), Insert [`insert`](BezierOutput::insert) halfway along the segment leaving the picked anchor; -/// Escape deselects. +/// Escape leaves the selection and goes to the window. /// - The anchor tools ([`BezierTool::AddAnchor`], [`BezierTool::DeleteAnchor`], [`BezierTool::AutoAddDelete`]) and /// [`BezierTool::Curvature`] take only a press that hits what they edit, and draw the [`HitMark`] of what a press /// would take under the pointer. [`segment_mark`](Self::segment_mark), [`anchors`](Self::anchors) and @@ -1121,9 +1121,6 @@ impl<'a> BezierOverlay<'a> { self.report.delete = Some(AnchorDelete::new(path, self.selection.anchors.clone(), true)); } } - if keyed && cx.gesture().is_none() && cx.intents().take(Intent::Cancel) && *self.selection != PathSelection::default() { - self.report.select = Some(PathSelection::default()); - } } /// The path ⌘A selects: the selection's, else the picked part's, else the only one. diff --git a/crates/draw/src/ui/pen/bezier/tools.rs b/crates/draw/src/ui/pen/bezier/tools.rs index 6297be197f..e2753753cf 100644 --- a/crates/draw/src/ui/pen/bezier/tools.rs +++ b/crates/draw/src/ui/pen/bezier/tools.rs @@ -57,7 +57,7 @@ impl BezierTool { matches!(self, BezierTool::AddAnchor | BezierTool::DeleteAnchor | BezierTool::AutoAddDelete) } - /// Whether the tool has the arrow, ⌘A and Esc keys: Direct, Convert and Curvature. Add and Delete have Delete + /// Whether the tool has the arrow and ⌘A keys: Direct, Convert and Curvature. Add and Delete have Delete /// only, Auto Add/Delete none. pub(super) fn keyed(self) -> bool { matches!(self, BezierTool::Direct | BezierTool::Convert | BezierTool::Curvature) diff --git a/crates/draw/tests/it/bezier.rs b/crates/draw/tests/it/bezier.rs index b7fe52b2a2..57f21a5048 100644 --- a/crates/draw/tests/it/bezier.rs +++ b/crates/draw/tests/it/bezier.rs @@ -421,7 +421,7 @@ fn hit_test_matches_the_overlays_press_priority() { // ---- the anchor tools and the Curvature tool ---- -// Arrows, select all and Escape belong to Direct, Convert and Curvature; Add, Delete and Auto Add/Delete have none. +// Arrows and select all belong to Direct, Convert and Curvature; Add, Delete and Auto Add/Delete have none. #[trial] fn cmd_or_ctrl_with_page_down_on_a_focused_anchor_scrolls_the_canvas_and_picks_no_part() { @@ -1202,6 +1202,23 @@ fn arrow_keys_nudge_the_selected_anchors_and_shift_nudges_farther() { assert_eq!(h.state.borrow().changes.len(), 2, "one edit per press"); } +// Escape on a focused anchor leaves the anchor selection and the targeted path under Direct, Convert and Curvature; it +// goes on to the window. A key still reaches the overlay afterwards. +#[trial] +fn escape_on_a_focused_anchor_keeps_the_selection() { + for tool in [BezierTool::Direct, BezierTool::Convert, BezierTool::Curvature] { + let mut h = two_paths(); + h.update(|st| (st.tool, st.selection) = (tool, sel(1, &[(0, 1)]))); + h.fixture.key(egui::Key::Tab, egui::Modifiers::NONE).key(egui::Key::Tab, egui::Modifiers::NONE).settle(); + let before = h.state.borrow().selection.clone(); + assert!(before != PathSelection::default(), "{tool:?}: an anchor is selected"); + h.fixture.key(egui::Key::Escape, egui::Modifiers::NONE).settle(); + assert_eq!(h.state.borrow().selection, before, "{tool:?}: Escape keeps the selection"); + h.fixture.key(egui::Key::ArrowRight, egui::Modifiers::NONE).settle(); + assert!(h.last_change().is_some(), "{tool:?}: the overlay still has the keys"); + } +} + // A press belongs to the tool it began under: switching the host's tool in the middle of a drag leaves the drag its // own, and it commits as that tool's edit. #[trial]