Select Other: Shift and Ctrl add the choice to the selection, as a click does (#5258) (#5261)

* Select Other: Shift and Ctrl add the choice to the selection, as a click does

* Select Other: follow origin visibility rename in test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Select Other test: click away from the lines' midpoints, which are picks of their own now

---------

Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kai Evans
2026-10-25 05:47:20 +00:00
committed by GitHub
parent a49698ee3d
commit beb38b44aa
5 changed files with 105 additions and 22 deletions
+24 -5
View File
@@ -222,6 +222,12 @@ pub struct MenuState {
pub over_geometry: bool,
/// The plane under the cursor when the viewport menu opened: it offers a sketch on it.
pub plane: Option<String>,
/// Where the viewport menu opened and the keys held at that click (Select Other adds with
/// them).
opened: Option<(Pos2, crate::tool_modifiers::Held)>,
/// The viewport menu's right-click selected what was under it: where the menu opened, the
/// selection before and the one it made. Select Other puts the one before back.
picked: Option<(Pos2, Vec<Sel>, Vec<Sel>)>,
/// The button that opened the menu, when it toggles it: a press there is not a press outside,
/// so its click closes the menu instead of closing and reopening it (#1522).
opener: Option<Rect>,
@@ -1057,7 +1063,15 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {
app.repeat_last();
}
"ui.selectOther" => {
crate::select_other::open(app, at);
// The list picks instead of the right-click.
if let Some((opened, before, made)) = app.menu.picked.take()
&& opened == at
&& app.session.selection == made
{
let _ = app.run("select.set", json!({ "items": before }));
}
let held = app.menu.opened.filter(|(opened, _)| *opened == at).map(|(_, held)| held).unwrap_or_default();
crate::select_other::open(app, at, held);
}
"ui.delete" if item.params.is_some() => crate::delete::request(app, p),
"ui.delete" => delete(app),
@@ -1555,8 +1569,11 @@ fn context_target_selected(selection: &[Sel], target: &Sel) -> bool {
/// Open the viewport menu at a screen position. A right-click on something not selected
/// selects it first, so the menu is about what is under the cursor; a face or edge already in a
/// multi-selection keeps the whole selection (#3733).
pub fn open(app: &mut SolveApp, at: Pos2) {
/// multi-selection keeps the whole selection (#3733). `held`: the keys held at that click.
pub fn open(app: &mut SolveApp, at: Pos2, held: crate::tool_modifiers::Held) {
app.menu.opened = Some((at, held));
app.menu.picked = None;
let before = app.session.selection.clone();
app.menu.over_geometry = app.viewport.hover.is_some();
// A right-click leaves a plane unselected, but the menu offers a sketch on it.
app.menu.plane = app.viewport.hover.clone().and_then(|h| crate::viewport::candidate(app, &[h])).and_then(|(_, sel)| match sel {
@@ -1572,6 +1589,7 @@ pub fn open(app: &mut SolveApp, at: Pos2) {
&& !matches!(sel, Sel::Plane { .. } | Sel::Axis { .. })
{
let _ = app.run("select.set", json!({ "items": [sel] }));
app.menu.picked = Some((at, before, app.session.selection.clone()));
} else if app.session.active_sketch.is_some()
&& let Some(h) = app.viewport.hover.clone()
&& let Some((_, sel)) = crate::viewport::candidate(app, &[h])
@@ -1580,6 +1598,7 @@ pub fn open(app: &mut SolveApp, at: Pos2) {
&& !context_target_selected(&app.session.selection, &sel)
{
let _ = app.run("select.set", json!({ "items": [sel] }));
app.menu.picked = Some((at, before, app.session.selection.clone()));
}
open_for(app, at, Target::Viewport);
}
@@ -1764,7 +1783,7 @@ fn track_hold(app: &mut SolveApp, ctx: &egui::Context) {
app.menu.press = None;
} else if time - t0 > 0.35 {
app.menu.press = None;
open(app, p0);
open(app, p0, crate::tool_modifiers::Held::from_modifiers(ctx.input(|i| i.modifiers)));
app.menu.flick = true;
} else {
ctx.request_repaint_after(std::time::Duration::from_millis(30));
@@ -1792,7 +1811,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
&& app.synthetic.is_empty()
{
app.menu.pending = None;
if target == Target::Viewport { open(app, at) } else { open_for(app, at, target) }
if target == Target::Viewport { open(app, at, crate::tool_modifiers::Held::default()) } else { open_for(app, at, target) }
}
crate::browser::dims_overlay(app, ctx);
track_hold(app, ctx);
+2 -2
View File
@@ -152,11 +152,11 @@ fn right_click_on_a_selected_face_keeps_the_multi_selection() {
)
.unwrap();
app.viewport.hover = Some(Hit::Face { body: b.clone(), index: 0, point: Vec3::new(9.0, 9.0, 9.0) });
context_menu::open(&mut app, pos2(400.0, 300.0));
context_menu::open(&mut app, pos2(400.0, 300.0), Default::default());
assert_eq!(app.session.selection.len(), 2, "the right-click keeps the faces it is about: {:?}", app.session.selection);
// A face outside the selection is still picked, so its menu is about the face under the cursor.
app.viewport.hover = Some(Hit::Face { body: b, index: 2, point: Vec3::new(9.0, 9.0, 9.0) });
context_menu::open(&mut app, pos2(400.0, 300.0));
context_menu::open(&mut app, pos2(400.0, 300.0), Default::default());
assert_eq!(app.session.selection.len(), 1, "a face outside the selection is picked: {:?}", app.session.selection);
}
+22 -14
View File
@@ -10,7 +10,8 @@
//! so at most [`MAX_PER_KIND`] rows are kept per kind, nearest first, and the list reports how
//! many things there were in all.
//! - Hovering a row lights its entity up in the viewport; clicking it selects it (Shift/Ctrl add,
//! as clicks do) or, with a dialog open, gives it to the dialog's active selection input.
//! as clicks do, held then or at the click or press that opened the list) or, with a dialog
//! open, gives it to the dialog's active selection input.
//! Esc or a click elsewhere closes the list.
//! - Clicking again on the same spot with nothing changed selects the next thing in that list
//! (click cycling). The second click of a double-click keeps its own actions.
@@ -26,6 +27,7 @@ use std::hash::{Hash, Hasher};
use crate::SolveApp;
use crate::theme::Tokens;
use crate::tool_modifiers::Held;
use crate::viewport::{Hit, Proj};
/// How long the left button stays down, without moving, before the list opens.
@@ -60,6 +62,8 @@ pub struct Popup {
dialog: bool,
/// The browser's body highlight is ours to clear.
lit_body: bool,
/// The keys held at the press or click that opened it.
held: Held,
}
/// The last plain click, for cycling.
@@ -74,8 +78,8 @@ struct Cycle {
#[derive(Default)]
pub struct State {
pub popup: Option<Popup>,
/// A left press that may become a hold: where and when.
hold: Option<(Pos2, f64)>,
/// A left press that may become a hold: where, when and with which keys.
hold: Option<(Pos2, f64, Held)>,
/// The current press belongs to Select Other (it opened or closed the list): the viewport
/// doesn't also click, drag or box-select with it.
held: bool,
@@ -292,13 +296,14 @@ fn projection_now(app: &SolveApp) -> Option<Proj> {
app.viewport.rect.map(|r| crate::viewport::projection(app, r))
}
/// Open the list at a screen point; false (with a status message) when nothing is there.
pub fn open(app: &mut SolveApp, at: Pos2) -> bool {
/// Open the list at a screen point; false (with a status message) when nothing is there. `held`:
/// the keys held at the click that opened it.
pub fn open(app: &mut SolveApp, at: Pos2, held: Held) -> bool {
let Some(proj) = projection_now(app) else { return false };
open_with(app, &proj, at)
open_with(app, &proj, at, held)
}
fn open_with(app: &mut SolveApp, proj: &Proj, at: Pos2) -> bool {
fn open_with(app: &mut SolveApp, proj: &Proj, at: Pos2, held: Held) -> bool {
let (rows, total) = rows_capped(app, proj, at);
if rows.is_empty() {
app.set_status("Nothing to select here", false);
@@ -306,7 +311,7 @@ fn open_with(app: &mut SolveApp, proj: &Proj, at: Pos2) -> bool {
}
close(app);
app.viewport.select_other.popup =
Some(Popup { at, rows, total, hovered: None, revision: app.session.revision, dialog: app.dialog.is_some(), lit_body: false });
Some(Popup { at, rows, total, hovered: None, revision: app.session.revision, dialog: app.dialog.is_some(), lit_body: false, held });
true
}
@@ -325,10 +330,12 @@ pub fn is_open(app: &SolveApp) -> bool {
/// Pick row `i` of the open list and close it.
///
/// `add` / `toggle` match viewport selection (Shift pure-add, Primary toggle when
/// `selection_shift_add_only` is on).
/// `selection_shift_add_only` is on); the keys held when the list opened add too.
pub fn choose(app: &mut SolveApp, i: usize, add: bool, toggle: bool) -> Result<Row, String> {
let Some(p) = app.viewport.select_other.popup.as_ref() else { return Err("Select Other is not open".into()) };
let at = p.at;
let (opened_add, opened_toggle) = crate::tool_modifiers::selection_click(p.held, app.preferences.selection_shift_add_only);
let (add, toggle) = (add || opened_add, toggle || opened_toggle);
let row = p.rows.get(i).cloned().ok_or_else(|| format!("no row {i} (the list has {})", p.rows.len()))?;
close(app);
apply(app, &row, add, toggle);
@@ -373,7 +380,7 @@ pub fn control(app: &mut SolveApp, p: &Value) -> Result<Value, String> {
if app.viewport.rect.is_none() {
return Err("no viewport".into());
}
open(app, pos2(x as f32, y as f32));
open(app, pos2(x as f32, y as f32), Held::default());
return Ok(describe(app));
}
if let Some(i) = p.get("hover").and_then(Value::as_u64) {
@@ -417,16 +424,17 @@ pub fn track_hold(
&& app.dialog.as_ref().is_none_or(|d| d.wants_picks())
&& app.viewport.point_drag.is_none();
if pressed && inside && free && !navigating {
app.viewport.select_other.hold = hover.map(|p| (p, now));
let held = Held::from_modifiers(ctx.input(|i| i.modifiers));
app.viewport.select_other.hold = hover.map(|p| (p, now, held));
}
let mut opened = false;
if let Some((p0, t0)) = app.viewport.select_other.hold {
if let Some((p0, t0, held)) = app.viewport.select_other.hold {
let slop = ctx.options(|o| o.input_options.max_click_dist);
if !down || navigating || !free || hover.is_some_and(|p| p.distance(p0) > slop) {
app.viewport.select_other.hold = None;
} else if now - t0 >= HOLD_SECS {
app.viewport.select_other.hold = None;
opened = open_with(app, proj, p0);
opened = open_with(app, proj, p0, held);
app.viewport.select_other.held = true;
} else {
ctx.request_repaint_after(std::time::Duration::from_millis(30));
@@ -578,7 +586,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
}
let (pressed, pointer, mods) = ctx.input(|i| (i.pointer.any_pressed(), i.pointer.interact_pos(), i.modifiers));
if let Some(i) = picked {
let held = crate::tool_modifiers::Held::from_modifiers(mods);
let held = Held::from_modifiers(mods);
let (add, toggle) = crate::tool_modifiers::selection_click(held, app.preferences.selection_shift_add_only);
let _ = choose(app, i, add, toggle);
} else if pressed && !pointer.is_some_and(|q| resp.response.rect.contains(q)) {
+56
View File
@@ -28,6 +28,35 @@ fn curves(h: &Harness) -> Vec<String> {
h.app.session.selection.iter().filter_map(|s| if let Sel::SketchCurve { id } = s { Some(id.clone()) } else { None }).collect()
}
/// Two lines of the sketch's own apart from each other (`l1` on x 0–15, `l2` on x 25–40, at
/// y 10): screen points on each.
fn two_lines_apart() -> (Harness, Value, Value) {
let mut h = Harness::new();
h.app.set_origin_shown(false);
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
for (x0, x1) in [(0, 15), (25, 40)] {
h.app.run("sketch.line", json!({"points":[[x0,10],[x1,10]],"infer":false,"connect":false})).unwrap();
}
h.app.cam.distance = 100.0;
h.settle();
let at = |h: &mut Harness, x: f64| h.call("ui.at", json!({"sketch":[x,10]}))["result"].clone();
// Away from the midpoints (7.5 and 32.5), which are picks of their own.
let (at_a, at_b) = (at(&mut h, 3.0), at(&mut h, 37.0));
(h, at_a, at_b)
}
/// The open list's row of sketch curve `id`.
fn row_of(h: &Harness, id: &str) -> usize {
let rows = crate::select_other::describe(&h.app)["rows"].clone();
let sels: Vec<Sel> = rows.as_array().into_iter().flatten().filter_map(|r| serde_json::from_value(r["sel"].clone()).ok()).collect();
sels.iter().position(|s| matches!(s, Sel::SketchCurve { id: x } if x == id)).unwrap_or_else(|| panic!("no row for {id}: {rows}"))
}
fn sorted(mut v: Vec<String>) -> Vec<String> {
v.sort();
v
}
#[test]
fn holding_still_lists_both_coincident_lines_and_picks_the_one_underneath() {
let (mut h, at) = two_lines();
@@ -252,3 +281,30 @@ fn overlapping_midpoints_can_be_selected_individually_without_creating_points()
assert_eq!(h.app.session.doc.to_json(), before);
assert_eq!(h.app.session.undo.len(), undo);
}
#[test]
fn select_other_opened_with_shift_adds_its_choice_to_the_selection() {
// From the viewport menu, opened by a Shift right-click: the right-click's own pick doesn't
// stay, and the choice adds without Shift still held.
let (mut h, at_a, at_b) = two_lines_apart();
h.step(&json!({"click": at_a})).unwrap();
assert_eq!(curves(&h), ["l1"]);
h.frames(30);
h.step(&json!({"click": at_b, "button": "right", "shift": true})).unwrap();
let r = h.call("ui.menuPick", json!({"item": "ui.selectOther"}));
assert_eq!(r["ok"], true, "{r}");
assert_eq!(curves(&h), ["l1"], "opening the list put the selection back");
let i = row_of(&h, "l2");
h.step(&json!({"click": {"handle": format!("select_other:{i}")}})).unwrap();
assert_eq!(sorted(curves(&h)), ["l1", "l2"]);
// By press and hold with Shift.
h.frames(30);
h.step(&json!({"click": at_a})).unwrap();
assert_eq!(curves(&h), ["l1"]);
h.frames(30);
h.step(&json!({"hold": at_b, "shift": true})).unwrap();
assert!(crate::select_other::is_open(&h.app));
let i = row_of(&h, "l2");
h.step(&json!({"click": {"handle": format!("select_other:{i}")}})).unwrap();
assert_eq!(sorted(curves(&h)), ["l1", "l2"]);
}
+1 -1
View File
@@ -3431,7 +3431,7 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
if app.tool.is_some() {
crate::tools::finish(app);
} else if app.dialog.is_none() {
crate::context_menu::open(app, p);
crate::context_menu::open(app, p, held_mods);
}
}
}