Browser: Shift+click above the anchor selects the whole range (#4991) (#4997)

* claim: #4991

* Browser: Shift+click above the anchor selects the whole range (#4991)

The browser rebuilds its row order while drawing, and a Shift click looked
the anchor up in that half-built list, so an anchor further down was not
there yet and only the clicked row was selected. Resolve the range against
the previous frame's complete row order instead.
This commit is contained in:
raykholo
2026-10-23 13:43:47 +00:00
committed by GitHub
parent 2f55a39c9c
commit 9e20a373ca
2 changed files with 46 additions and 5 deletions
+15 -5
View File
@@ -104,6 +104,9 @@ pub struct TreeState {
anchor: Option<String>,
/// Row keys in drawing order this frame (for Shift ranges).
order: Vec<String>,
/// The previous frame's complete row order: a Shift click resolves its range here, since
/// this frame's `order` does not yet hold the rows below the clicked one (#4991).
order_prev: Vec<String>,
}
/// Moving an occurrence: the offsets typed so far (pending until Capture Position).
@@ -478,10 +481,8 @@ fn click_select(app: &mut SolveApp, ui: &egui::Ui, key: String, sel: Option<Sel>
if mods.shift
&& let Some(a) = app.tree.anchor.clone()
{
let order = app.tree.order.clone();
if let (Some(i), Some(j)) = (order.iter().position(|k| *k == a), order.iter().position(|k| *k == key)) {
let (lo, hi) = (i.min(j), i.max(j));
let items: Vec<Sel> = order[lo..=hi].iter().filter_map(|k| sel_of_key(k)).collect();
let items = shift_range(&app.tree.order_prev, &a, &key).or_else(|| shift_range(&app.tree.order, &a, &key));
if let Some(items) = items {
let _ = app.run("select.set", json!({ "items": items, "add": mods.command || mods.ctrl }));
return;
}
@@ -502,6 +503,15 @@ fn click_select(app: &mut SolveApp, ui: &egui::Ui, key: String, sel: Option<Sel>
}
}
/// The selectable rows from `anchor` to `key` (either way round) in a row order, or `None`
/// when the order lacks either of them.
fn shift_range(order: &[String], anchor: &str, key: &str) -> Option<Vec<Sel>> {
let i = order.iter().position(|k| k == anchor)?;
let j = order.iter().position(|k| k == key)?;
let rows = order.get(i.min(j)..=i.max(j))?;
Some(rows.iter().filter_map(|k| sel_of_key(k)).collect())
}
fn sel_of_key(k: &str) -> Option<Sel> {
if let Some((_, id)) = k.rsplit_once("/s:") {
return id.parse().ok().map(|id| Sel::Feature { id });
@@ -693,7 +703,7 @@ pub(crate) fn resize_column(app: &mut SolveApp, ui: &egui::Ui, rect: Rect, width
pub fn browser(app: &mut SolveApp, ui: &mut egui::Ui) {
let available = ui.available_rect_before_wrap();
let t = Tokens::get();
app.tree.order.clear();
app.tree.order_prev = std::mem::take(&mut app.tree.order);
DRAWN.with(|d| d.borrow_mut().clear());
OCCURRENCES.with(|d| d.borrow_mut().clear());
let mut acts = Actions::default();
+31
View File
@@ -158,6 +158,37 @@ mod tests {
assert_eq!(h.app.session.undo.len(), undo);
}
#[test]
fn browser_feature_shift_click_selects_the_range_up_and_down() {
let mut h = Harness::new();
let ids: Vec<u64> = (0..5)
.map(|i| {
h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":format!("B{i}")})).unwrap()["feature"].as_u64().unwrap()
})
.collect();
h.app.tree.expanded.insert("c0/features".into());
h.frames(2);
let row = |id: u64| json!({"handle": format!("row:browser-feature:c0:{id}")});
let all: Vec<Sel> = ids.iter().map(|&id| Sel::Feature { id }).collect();
let sorted = |s: &[Sel]| {
let mut v = s.to_vec();
v.sort_by_key(|x| format!("{x:?}"));
v
};
// Up: anchor on the last row, Shift+click the first.
h.step(&json!({"click": row(ids[4])})).unwrap();
h.frames(2);
h.step(&json!({"click": row(ids[0]), "shift": true})).unwrap();
h.frames(2);
assert_eq!(sorted(&h.app.session.selection), sorted(&all), "Shift+click above the anchor");
// Down: anchor on the first row, Shift+click the last.
h.step(&json!({"click": row(ids[0])})).unwrap();
h.frames(2);
h.step(&json!({"click": row(ids[4]), "shift": true})).unwrap();
h.frames(2);
assert_eq!(sorted(&h.app.session.selection), sorted(&all), "Shift+click below the anchor");
}
fn find(app: &mut SolveApp, feature: u64, body: &str) {
let state = app.session.world_state();
let model_body = state.body(body).unwrap();