mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 17:56:50 -06:00
Libraries: a plain click sets where a Shift-click range starts
A plain click on an item in the library panel selected the item but did not record it as the anchor that a Shift-click ranges from. A later Shift-click then selected only the clicked item, or ranged from an older anchor set by an earlier Cmd/Ctrl-click or folder click. This applied to swatch libraries and graphic style libraries. Every click on an item or folder now goes through click_selection, as in the Swatches panel. A plain click still selects the item alone and adds and applies it.
This commit is contained in:
@@ -274,10 +274,10 @@ fn body<K: LibraryKind>(app: &mut VectorcraftApp, ui: &mut Ui, id: &str, lib: &K
|
||||
});
|
||||
});
|
||||
if let Some((name, folder, m)) = clicked {
|
||||
// A plain click on an item adds and applies it; folders and modifier clicks select.
|
||||
// A plain click on an item also adds and applies it; folders and modifier clicks only select.
|
||||
let only_select = folder || m.shift || m.command;
|
||||
let order: Vec<&str> = rows.iter().map(|r| r.name).collect();
|
||||
let sel = if only_select { click_selection(ui, &key::<K>("anchor"), selected.clone(), &order, &name, m) } else { vec![name.clone()] };
|
||||
let sel = click_selection(ui, &key::<K>("anchor"), selected, &order, &name, m);
|
||||
set_selection::<K>(ui.ctx(), id, sel);
|
||||
if !only_select {
|
||||
K::click(app, ui, id, &name);
|
||||
@@ -485,6 +485,26 @@ mod tests {
|
||||
assert!(selection::<SwatchLibraries>(&ctx, "brights").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_plain_click_sets_where_a_shift_click_range_starts() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
app.run("window.swatchLibrary", json!({"library": "pastels"})).unwrap();
|
||||
let (_, lib) = SwatchLibraries::get(&app, "pastels").unwrap();
|
||||
let order: Vec<String> = SwatchLibraries::rows(&lib, "").iter().map(|r| r.name.to_string()).collect();
|
||||
click(&mut app, &ctx, &order[1], Modifiers::NONE, 0.0);
|
||||
click(&mut app, &ctx, &order[4], Modifiers::SHIFT, 2.0);
|
||||
assert_eq!(selection::<SwatchLibraries>(&ctx, "pastels"), order[1..=4], "the range starts at the plain click");
|
||||
// A plain click after a Cmd/Ctrl-click moves the anchor from the Cmd/Ctrl-clicked item.
|
||||
click(&mut app, &ctx, &order[8], Modifiers::COMMAND, 4.0);
|
||||
click(&mut app, &ctx, &order[2], Modifiers::NONE, 6.0);
|
||||
click(&mut app, &ctx, &order[3], Modifiers::SHIFT, 8.0);
|
||||
assert_eq!(selection::<SwatchLibraries>(&ctx, "pastels"), order[2..=3]);
|
||||
let d = &app.session.doc().unwrap().doc;
|
||||
assert!(d.swatch(&order[2]).is_some(), "a plain click still adds the swatch");
|
||||
assert!(d.swatch(&order[3]).is_none(), "a Shift-click only selects");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_filters_list_view_and_arrows_step_through_the_libraries() {
|
||||
let mut app = app();
|
||||
|
||||
Reference in New Issue
Block a user