From ffeade05856b040e83702175025aaebf936cf155 Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 27 Nov 2026 00:42:24 -0600 Subject: [PATCH 1/3] feat(ui): Ctrl+A selects every feature, and Copy and Paste act on layers in the layer list Two more keys follow the pane in use (#2944). Ctrl/Cmd+A is a default key for select.all: every feature of the active layer, or of the layer the attribute table shows while the table is in use. A text field keeps the key, and it is left alone in a layout, in ModelBuilder and in a standalone table's view. It waits for a click of its own frame, as Delete does. In the layer list, Copy and Paste act on the layers picked there, as the layer menu's Copy Layer and Paste Layer do; elsewhere they act on features as before. Copying layers puts their names on the clipboard, and Paste adds the layers only while the clipboard still holds them, so whatever was copied last is what is pasted. Cut in the layer list does nothing and says why: it cut the map's selected features before. --- crates/ui-egui/src/chrome.rs | 101 +++++++++++++++++++++--- crates/ui-egui/src/inuse.rs | 149 +++++++++++++++++++++++++++++++++++ crates/ui-egui/src/keymap.rs | 3 + crates/ui-egui/src/lib.rs | 4 + crates/ui-egui/src/panes.rs | 43 ++++++++-- docs/user-guide/index.md | 11 ++- 6 files changed, 293 insertions(+), 18 deletions(-) diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 64d4fec82e..0e9726d450 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -937,6 +937,12 @@ pub fn shortcuts(app: &mut RustGisApp, ctx: &egui::Context) { { continue; } + // Select All is the text's while a text field has the focus, and is left alone where + // there are no features to select: in a layout, in ModelBuilder and in a standalone + // table's view. + if b.command == "select.all" && select_all_left_alone(app, pane, typing || text_field) { + continue; + } // Duplicating needs a selected layout element, and not a text field being typed in; // otherwise the key is left alone. if b.command == "layout.duplicateElement" && (!element || typing) { @@ -992,13 +998,23 @@ pub fn shortcuts(app: &mut RustGisApp, ctx: &egui::Context) { } } } - // Clipboard keys arrive as events, not key presses. + // Clipboard keys arrive as events, not key presses. In the layer list they act on the + // layers a click picks, so one that came while a click was under way waits for the + // click to be taken, as Delete does. + let mut nth = 0; for e in &i.events { - match e { - egui::Event::Copy => run.push(("ui.copy".into(), Value::Null, pane)), - egui::Event::Cut => run.push(("ui.cut".into(), Value::Null, pane)), - egui::Event::Paste(text) => run.push(("edit.paste".into(), json!({"text": text}), pane)), - _ => {} + let (id, params) = match e { + egui::Event::Copy => ("ui.copy", Value::Null), + egui::Event::Cut => ("ui.cut", Value::Null), + egui::Event::Paste(text) => ("edit.paste", json!({"text": text})), + _ => continue, + }; + let (key_pane, after_click) = crate::inuse::clipboard(app, nth).unwrap_or((pane, false)); + nth += 1; + if key_pane == Pane::Layers && after_click { + late.push(Late { id: id.into(), params, pane: key_pane, chord: None }); + } else { + run.push((id.into(), params, key_pane)); } } } @@ -1063,12 +1079,19 @@ fn text_takes(chord: Option, typing: bool, text_field: boo } } +/// Whether Select All's key is left alone, with `pane` in use: while text is typed or a text field +/// has the focus (`in_text`: the key selects its text), and where there are no features to select +/// (a layout, ModelBuilder, a standalone table's view). +fn select_all_left_alone(app: &RustGisApp, pane: Pane, in_text: bool) -> bool { + in_text || app.session.active_layout.is_some() || app.mb.shown() || (pane == Pane::Table && app.session.table_layer.is_none()) +} + /// Whether command `id` acts on what a click picks (the layer, the tab, the features). A frame /// reads its keys before it draws the panes, where a click is taken, so on a slow frame a layer /// clicked and Delete pressed would remove the layer picked before: the key of such a command, /// pressed while a click is under way, runs in [`late_keys`]. fn follows_click(id: &str) -> bool { - matches!(id, "edit.delete" | "layer.rename") + matches!(id, "edit.delete" | "layer.rename" | "select.all") } /// Runs the keys [`shortcuts`] left for the end of the frame, now that the panes have taken its @@ -1082,8 +1105,12 @@ pub fn late_keys(app: &mut RustGisApp, ctx: &egui::Context) { return; } let (typing, text_field) = (typing(app, ctx), ctx.text_edit_focused()); - let run: Vec<(String, Value, Pane)> = - late.into_iter().filter(|key| !text_takes(key.chord, typing, text_field)).map(|key| (key.id, key.params, key.pane)).collect(); + // Select All is judged again, now that the click may have put the cursor in a text field or + // brought a layout into view. + let dropped = |key: &Late| { + text_takes(key.chord, typing, text_field) || (key.id == "select.all" && select_all_left_alone(app, key.pane, typing || text_field)) + }; + let run: Vec<(String, Value, Pane)> = late.into_iter().filter(|key| !dropped(key)).map(|key| (key.id, key.params, key.pane)).collect(); // The panes and dialogs were drawn before these keys run: another frame shows what they did. if !run.is_empty() { ctx.request_repaint(); @@ -1146,6 +1173,21 @@ fn run_keys(app: &mut RustGisApp, ctx: &egui::Context, run: &[(String, Value, Pa remove_picked_layers(app); continue; } + // There, Copy, Cut and Paste are for the layers picked too, as the layer menu's Copy + // Layer and Paste Layer are (#2944). + if pane == Pane::Layers && layer_clipboard_key(app, id, &p) { + continue; + } + // In the attribute table, Select All is for the layer it shows, which needn't be the + // active one. + if id == "select.all" + && p.get("layer").is_none() + && pane == Pane::Table + && let Some(layer) = app.session.table_layer + { + let _ = app.run("select.all", json!({"layer": layer})); + continue; + } // On the tabs, and in a layout, Rename (F2) is for the map or layout in view, as a // double-click on its tab is; elsewhere it renames the active layer (below). if id == "layer.rename" @@ -1187,7 +1229,7 @@ fn run_keys(app: &mut RustGisApp, ctx: &egui::Context, run: &[(String, Value, Pa continue; } // Pasting text that isn't features (a stray copy from elsewhere) does nothing. - if id == "edit.paste" && !p.get("text").and_then(Value::as_str).is_some_and(|t| t.trim_start().starts_with('{')) { + if id == "edit.paste" && !pastes_features(&p) { continue; } // Exhausted undo/redo shortcuts are inert, like their disabled toolbar buttons. @@ -1237,6 +1279,45 @@ fn remove_picked_layers(app: &mut RustGisApp) { } } +/// Copy, Cut and Paste in the layer list (`id`: `ui.copy`, `ui.cut`, `edit.paste` with the +/// clipboard's text in `p`); false for one that isn't the list's to take. +/// +/// Copy copies the layers picked, as the menu's Copy Layer does, and puts their names on the +/// clipboard as text. Paste adds the copied layers above the active one while the clipboard still +/// holds those names: anything copied since (features, text in another program) is the newer +/// copy, and goes the way a paste goes anywhere else. Cut does nothing and says so: a held key +/// repeats it, and each removal makes the next layer the active one, so it would take the list +/// from there down. It must not cut the map's selected features either. +fn layer_clipboard_key(app: &mut RustGisApp, id: &str, p: &Value) -> bool { + match id { + "ui.copy" => { + let picked = app.session.selected_layers(); + if let Some(why) = why_disabled(app, "layer.remove") { + cannot_run(app, tl_raw!("Copy Layers"), tl_raw!(why)); + } else { + crate::panes::copy_layers(app, json!({"layer": picked})); + } + true + } + "ui.cut" => { + cannot_run(app, tl_raw!("Cut"), tl_raw!("a layer isn't cut: copy it, then remove it with Delete")); + true + } + "edit.paste" if crate::panes::pastes_copied_layers(app, p.get("text").and_then(Value::as_str).unwrap_or_default()) => { + let at = app.session.active_layer.map_or(Value::Null, |layer| crate::panes::paste_above(app, layer)); + let _ = app.run("layer.paste", at); + true + } + _ => false, + } +} + +/// Whether a Paste's text is features (what Copy puts on the clipboard for them), not a stray +/// copy from elsewhere. +fn pastes_features(p: &Value) -> bool { + p.get("text").and_then(Value::as_str).is_some_and(|t| t.trim_start().starts_with('{')) +} + /// The dialog Rename (F2) opens for the map or layout in view, when `pane` is one where the key /// is about it rather than the active layer: the tabs, or a layout. `None` elsewhere, and with /// ModelBuilder in view (a model is named in its own toolbar). diff --git a/crates/ui-egui/src/inuse.rs b/crates/ui-egui/src/inuse.rs index 4cba32e2d4..0d326c546f 100644 --- a/crates/ui-egui/src/inuse.rs +++ b/crates/ui-egui/src/inuse.rs @@ -73,6 +73,9 @@ pub struct InUse { /// The keys that are down, each with the pane that was in use as it went down: a held key's /// repeats are that pane's. held: Vec<(Key, Pane)>, + /// This frame's Copy, Cut and Paste, in order: the pane in use as each came, and whether a + /// click was under way (as [`Press`] says of a key). + clipboard: Vec<(Pane, bool)>, /// This frame's keys kept until its panes are drawn, and the dialogs that were up as they /// were pressed (a number that differs when they do). late: Vec, @@ -132,6 +135,8 @@ pub fn follow(app: &mut RustGisApp, ctx: &egui::Context) { // Each key going down (with its modifiers, how many of them came before and whether a click // was under way) or up (`None`), in order. let mut keys: Vec<(Key, Option<(Modifiers, usize, bool)>)> = Vec::new(); + // Each Copy, Cut and Paste: how many of them came before it, and whether a click was under way. + let mut clips: Vec<(usize, bool)> = Vec::new(); ctx.input(|i| { for e in &i.events { match e { @@ -155,6 +160,7 @@ pub fn follow(app: &mut RustGisApp, ctx: &egui::Context) { keys.push((*key, Some((*modifiers, worked.len(), clicked)))); } egui::Event::Key { key, pressed: false, .. } => keys.push((*key, None)), + egui::Event::Copy | egui::Event::Cut | egui::Event::Paste(_) => clips.push((worked.len(), clicked)), _ => {} } } @@ -184,6 +190,8 @@ pub fn follow(app: &mut RustGisApp, ctx: &egui::Context) { }); } in_use.pane = panes.last().copied().unwrap_or_default(); + in_use.clipboard = + clips.into_iter().map(|(worked, after_click)| (panes.get(worked).copied().unwrap_or(in_use.pane), after_click)).collect(); in_use.presses.clear(); for (key, pressed) in keys { in_use.held.retain(|(held, _)| *held != key); @@ -223,6 +231,12 @@ pub fn press(app: &RustGisApp, key: Key, chord: Option) -> Option
 Option<(Pane, bool)> {
+    app.ui.in_use.clipboard.get(nth).copied()
+}
+
 /// Keeps this frame's keys that run after its panes are drawn ([`crate::chrome::late_keys`]),
 /// with `dialogs`, a number for the dialogs that are up now.
 pub fn keep_late(app: &mut RustGisApp, late: Vec, dialogs: u64) {
@@ -562,6 +576,141 @@ mod tests {
         assert!(h.state().session.project.layouts[li].element(title).is_some(), "Delete didn't reach the element behind the question");
     }
 
+    /// Ctrl+A selects every feature of the active layer; with the attribute table in use, of the
+    /// layer it shows. A text field keeps the key for its text, and a layout has nothing to select.
+    #[test]
+    fn ctrl_a_selects_every_feature_of_the_layer() {
+        let mut app = RustGisApp::with_sample();
+        app.run("layer.select", json!({"layer": "Rivers"})).unwrap();
+        let mut h = window(app);
+        let selected = |h: &Window, name: &str| {
+            h.state().session.map().layer_by_name(name).map(|l| (l.selection.len(), l.dataset.features.len())).unwrap()
+        };
+        let all = |h: &Window, name: &str| {
+            let (selected, rows) = selected(h, name);
+            rows > 0 && selected == rows
+        };
+        let ctrl_a = |h: &mut Window| {
+            h.key_press_modifiers(Modifiers::COMMAND, Key::A);
+            h.run_steps(2);
+        };
+        ctrl_a(&mut h);
+        assert!(all(&h, "Rivers"), "every river is selected: {:?}", selected(&h, "Rivers"));
+
+        // A layer clicked and the key pressed in one frame: the key is for the layer clicked.
+        h.state_mut().run("select.clear", Value::Null).unwrap();
+        h.run_steps(2);
+        let a = |pressed| Event::Key { key: Key::A, physical_key: None, pressed, repeat: false, modifiers: Modifiers::COMMAND };
+        let lakes = h.get_by_label("Lakes").rect().center();
+        in_one_frame(&mut h, [Event::PointerMoved(lakes), button(lakes, true), button(lakes, false), a(true), a(false)]);
+        assert!(all(&h, "Lakes"), "every lake is selected: {:?}", selected(&h, "Lakes"));
+        assert_eq!(selected(&h, "Rivers").0, 0, "and no river, the layer picked before");
+
+        // The table of another layer, pressed in: the key is for the layer it shows.
+        h.state_mut().run("select.clear", Value::Null).unwrap();
+        h.state_mut().run("table.open", json!({"layer": "Cities"})).unwrap();
+        h.state_mut().run("layer.select", json!({"layer": "Rivers"})).unwrap();
+        h.run_steps(3);
+        let table = rect(&h, Pane::Table);
+        press(&mut h, table.center());
+        assert_eq!(pane(h.state()), Pane::Table);
+        ctrl_a(&mut h);
+        assert!(all(&h, "Cities"), "every city is selected: {:?}", selected(&h, "Cities"));
+        assert_eq!(selected(&h, "Rivers").0, 0, "the active layer's features aren't");
+
+        // In a text field the key selects its text.
+        h.state_mut().run("select.clear", Value::Null).unwrap();
+        h.run_steps(2);
+        let filter = rect(&h, Pane::Layers).center_top() + vec2(0.0, 20.0);
+        press(&mut h, filter);
+        assert!(h.ctx.egui_wants_keyboard_input(), "the click is in the filter box");
+        ctrl_a(&mut h);
+        assert_eq!((selected(&h, "Cities").0, selected(&h, "Rivers").0), (0, 0), "Ctrl+A in a text field selects no feature");
+        h.key_press(Key::Escape);
+        h.run_steps(2);
+        // Nor with the click that puts the cursor there in the key's own frame.
+        let map = rect(&h, Pane::View).center();
+        press(&mut h, map);
+        in_one_frame(&mut h, [Event::PointerMoved(filter), button(filter, true), button(filter, false), a(true), a(false)]);
+        assert!(h.ctx.egui_wants_keyboard_input(), "the click is in the filter box");
+        assert_eq!((selected(&h, "Cities").0, selected(&h, "Rivers").0, selected(&h, "Lakes").0), (0, 0, 0));
+        h.key_press(Key::Escape);
+        h.run_steps(2);
+
+        // A layout has no features to select.
+        h.state_mut().run("layout.new", json!({"name": "Sheet"})).unwrap();
+        h.run_steps(3);
+        ctrl_a(&mut h);
+        assert_eq!((selected(&h, "Cities").0, selected(&h, "Rivers").0), (0, 0), "Ctrl+A in a layout selects no feature");
+    }
+
+    /// Copy and Paste in the layer list are for the layers picked there, and for features
+    /// everywhere else; what was copied after the layers is what Paste takes, in the list too. Cut
+    /// in the list cuts nothing, layers or features, and says so.
+    #[test]
+    fn copy_and_paste_in_the_layer_list_are_for_layers() {
+        let mut app = RustGisApp::with_sample();
+        app.run("edit.enable", json!({"on": true})).unwrap();
+        app.run("select.rows", json!({"layer": "Cities", "rows": [0]})).unwrap();
+        let mut h = window(app);
+        let before = layer_names(&h);
+        let rivers = |h: &Window| layer_names(h).iter().filter(|n| n.starts_with("Rivers")).count();
+        let clip = |h: &mut Window, event: Event| {
+            h.event(event);
+            h.run_steps(2);
+        };
+
+        // On the map, Copy is for the selected feature: no layer is copied.
+        clip(&mut h, Event::Copy);
+        assert!(h.state().session.layer_clipboard.is_none());
+
+        // In the list, Copy copies the layer picked and Paste adds the copy; one Undo takes it out.
+        h.get_by_label("Rivers").click();
+        h.run_steps(2);
+        clip(&mut h, Event::Copy);
+        assert!(h.state().session.layer_clipboard.is_some(), "the layer was copied");
+        assert_eq!(layer_names(&h), before, "copying changes nothing");
+        clip(&mut h, Event::Paste("Rivers".into()));
+        assert_eq!((layer_names(&h).len(), rivers(&h)), (before.len() + 1, 2), "{:?}", layer_names(&h));
+        h.state_mut().run("edit.undo", Value::Null).unwrap();
+        h.run_steps(2);
+        assert_eq!(layer_names(&h), before);
+
+        // Text copied elsewhere since: the layers aren't the last thing copied any more.
+        clip(&mut h, Event::Paste("something else".into()));
+        assert_eq!(layer_names(&h), before, "a stale copy of layers isn't pasted");
+
+        // Features copied since: Paste in the list adds them, not the layer copied before.
+        let features = h.state_mut().run("edit.copy", Value::Null).unwrap()["text"].as_str().unwrap().to_string();
+        assert!(features.trim_start().starts_with('{'));
+        h.get_by_label("Cities").click();
+        h.run_steps(2);
+        let cities = |h: &Window| h.state().session.map().layer_by_name("Cities").unwrap().dataset.features.len();
+        let n = cities(&h);
+        clip(&mut h, Event::Paste(features));
+        assert_eq!(layer_names(&h), before, "no layer is pasted");
+        assert_eq!(cities(&h), n + 1, "the copied feature is");
+
+        // Cut in the list removes no layer and cuts no feature, and says why.
+        h.get_by_label("Rivers").click();
+        h.run_steps(2);
+        let n = cities(&h);
+        clip(&mut h, Event::Cut);
+        assert_eq!((layer_names(&h), cities(&h)), (before.clone(), n));
+        assert!(
+            says(&h, "Cut: a layer isn't cut: copy it, then remove it with Delete"),
+            "{:?}",
+            h.state().map.toasts.iter().map(|t| &t.text).collect::>()
+        );
+
+        // A layer clicked and Copy in one frame: the layer just clicked is the one copied.
+        let lakes = h.get_by_label("Lakes").rect().center();
+        in_one_frame(&mut h, [Event::PointerMoved(lakes), button(lakes, true), button(lakes, false), Event::Copy]);
+        let copied: Vec =
+            h.state().session.layer_clipboard.as_ref().map(|c| c.layers.iter().map(|l| l.name.clone()).collect()).unwrap_or_default();
+        assert_eq!(copied, ["Lakes"]);
+    }
+
     /// What ends the layer list's turn without a press in another pane, and what doesn't: its
     /// own menu keeps it; a dialog, another project and the pane closing end it.
     #[test]
diff --git a/crates/ui-egui/src/keymap.rs b/crates/ui-egui/src/keymap.rs
index be83f2d172..849decbe85 100644
--- a/crates/ui-egui/src/keymap.rs
+++ b/crates/ui-egui/src/keymap.rs
@@ -35,6 +35,9 @@ const DEFAULTS: &[(&str, &str, &str)] = &[
     ("Home", "map.zoomFull", ""),
     ("Escape", "tool.set", r#"{"tool":"explore"}"#),
     ("Delete", "edit.delete", ""),
+    // Every feature of the active layer; a text field with the focus keeps the key for its text
+    // (see `chrome`).
+    ("Mod+A", "select.all", ""),
     ("Mod+D", "layout.duplicateElement", ""),
     // The active layer in the Layers pane's outline, as a word processor's outline keys (#836).
     ("Alt+Shift+ArrowRight", "layer.indent", ""),
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 8966523c7b..cff6c1c24f 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1189,6 +1189,9 @@ pub struct UiState {
     pub dynamic_text: Option<&'static str>,
     /// Text to put on the system clipboard at the end of the frame.
     pub copy_out: Option,
+    /// The text the last copy of layers put on the clipboard (their names): while the clipboard
+    /// still holds it, a Paste key in the layer list pastes those layers.
+    pub(crate) layers_copied_as: Option,
     /// A web page to open at the end of the frame.
     pub open_url: Option,
     /// An image to put on the system clipboard at the end of the frame.
@@ -1281,6 +1284,7 @@ impl Default for UiState {
             pane_rects: [None; 2],
             in_use: inuse::InUse::default(),
             copy_out: None,
+            layers_copied_as: None,
             open_url: None,
             copy_image: None,
             pending_picture: None,
diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs
index d1698c553e..ad7aafacf8 100644
--- a/crates/ui-egui/src/panes.rs
+++ b/crates/ui-egui/src/panes.rs
@@ -963,6 +963,39 @@ fn paste_label(app: &RustGisApp) -> &'static str {
     }
 }
 
+/// Copies layers (`layer.copy` with `params`) and puts their names on the clipboard as text, one a
+/// line: a paste elsewhere gives the names, and a Paste key in the layer list can tell whether the
+/// layers are still the last thing copied ([`pastes_copied_layers`]). A copy with no layer in it
+/// (an empty group) leaves the clipboard alone. Whether they were copied.
+pub(crate) fn copy_layers(app: &mut RustGisApp, params: Value) -> bool {
+    let Ok(copied) = app.run("layer.copy", params) else { return false };
+    let names: Vec<&str> = copied["layers"].as_array().into_iter().flatten().filter_map(Value::as_str).collect();
+    let names = names.join("\n");
+    app.ui.layers_copied_as = (!names.trim().is_empty()).then(|| names.clone());
+    if app.ui.layers_copied_as.is_some() {
+        app.ui.copy_out = Some(names);
+    }
+    true
+}
+
+/// Whether a Paste key in the layer list, with `text` on the clipboard, pastes the copied layers:
+/// while the clipboard still holds what the last copy of layers put there (line ends aside, which
+/// a clipboard may change). Features or text copied since are the newer copy.
+pub(crate) fn pastes_copied_layers(app: &RustGisApp, text: &str) -> bool {
+    let lines = |text: &str| text.lines().map(str::trim_end).filter(|line| !line.is_empty()).map(str::to_owned).collect::>();
+    app.session.layer_clipboard.is_some() && app.ui.layers_copied_as.as_deref().is_some_and(|names| lines(names) == lines(text))
+}
+
+/// Where `layer.paste` puts the copies when they are pasted on layer `id`: above it, or at the
+/// top of its group.
+pub(crate) fn paste_above(app: &RustGisApp, id: u32) -> Value {
+    let m = app.session.map();
+    match m.group_of(id) {
+        Some(g) => json!({"group": g.id}),
+        None => json!({"to": m.layer_index(id).unwrap_or(0)}),
+    }
+}
+
 /// A button pasting the copied layers (#491) on top of the map in view, off while none are.
 fn paste_layers_button(app: &mut RustGisApp, ui: &mut Ui) {
     if ui.add_enabled(app.session.layer_clipboard.is_some(), egui::Button::new(paste_label(app))).clicked() {
@@ -1411,7 +1444,7 @@ fn layer_group_row(
             }
             ui.separator();
             if ui.button(tl!("Copy Group")).clicked() {
-                let _ = app.run("layer.copy", json!({"group": group.id}));
+                copy_layers(app, json!({"group": group.id}));
                 ui.close();
             }
             if ui.add_enabled(app.session.layer_clipboard.is_some(), egui::Button::new(paste_label(app))).clicked() {
@@ -2567,15 +2600,11 @@ fn layer_menu(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, reorder: bool) {
     ui.separator();
     // Whole layers (#491): pasted on a layer, the copies go above it, or at the top of its group.
     if ui.button(tl!("Copy Layer")).clicked() {
-        let _ = app.run("layer.copy", json!({"layer": l.id}));
+        copy_layers(app, json!({"layer": l.id}));
         ui.close();
     }
     if ui.add_enabled(app.session.layer_clipboard.is_some(), egui::Button::new(paste_label(app))).clicked() {
-        let m = app.session.map();
-        let at = match m.group_of(l.id) {
-            Some(g) => json!({"group": g.id}),
-            None => json!({"to": m.layer_index(l.id).unwrap_or(0)}),
-        };
+        let at = paste_above(app, l.id);
         let _ = app.run("layer.paste", at);
         ui.close();
     }
diff --git a/docs/user-guide/index.md b/docs/user-guide/index.md
index 0c150a118d..94bae3db3c 100644
--- a/docs/user-guide/index.md
+++ b/docs/user-guide/index.md
@@ -552,7 +552,8 @@ with `{"layer":"parcels"}`.
 | ++alt+shift+right++ / ++alt+shift+left++ | Indent the active layer into the group above it / outdent it out of its group |
 | ++alt+shift+up++ / ++alt+shift+down++ | Move the active layer up / down one step in the Layers pane |
 | ++f2++ | Rename the active layer; on the map and layout tabs, and in a layout, the map or layout in view |
-| ++ctrl+c++ / ++ctrl+x++ / ++ctrl+v++ | Copy / Cut / Paste features |
+| ++ctrl+a++ | Select every feature of the active layer; in the attribute table, of the layer it shows; in a text field, its text |
+| ++ctrl+c++ / ++ctrl+x++ / ++ctrl+v++ | Copy / Cut / Paste features; in the layer list, Copy and Paste the selected layers |
 
 On macOS, ++cmd++ takes the place of ++ctrl++. **Help › Shortcuts** lists them all in the app,
 from the same table the app runs them from. While you type in a text field, undo and redo take
@@ -562,3 +563,11 @@ back its typing, not the project's last change.
 Click a layer in the Layers pane and ++delete++ removes it (Undo brings it back), whatever is
 selected on the map; click or scroll the map and it deletes the selected features again. When
 ++delete++ has nothing to act on, a notice says why.
+
+Copy and Paste follow it too. In the Layers pane they copy and paste the selected layers, as **Copy
+Layer** and **Paste Layer** in a layer's menu do: the copies go above the active layer, or at the
+top of its group. Copying layers puts their names on the clipboard as text, and Paste adds the
+layers while the clipboard still holds those names; features or text copied after that are what
+Paste takes next, in the Layers pane as on the map. Cut does nothing in the Layers pane: copy a
+layer, then remove it with ++delete++. ++ctrl+a++ is left alone in a layout and in ModelBuilder,
+where there are no features to select.

From 3def7d4b91ac9b771ab40d6b41c23fcbaa4d09be Mon Sep 17 00:00:00 2001
From: mavrick 
Date: Fri, 27 Nov 2026 01:29:53 -0600
Subject: [PATCH 2/3] fix(ui): Paste in the layer list takes the layers the
 clipboard names

The check compared the clipboard with text the interface remembered. A
script or the Assistant copying other layers since left that text as it
was, so Paste added layers the clipboard didn't name. It now compares
the clipboard with the names of the layers the session holds a copy of.

Select All is judged by the pane in use as its key came, not by the one
at the end of the frame, and clipboard keys after one that waits for a
click wait too, so they run in the order they came.
---
 crates/ui-egui/src/chrome.rs | 14 +++++++++-----
 crates/ui-egui/src/inuse.rs  |  5 +++++
 crates/ui-egui/src/lib.rs    |  4 ----
 crates/ui-egui/src/panes.rs  | 26 ++++++++++++++------------
 4 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs
index 0e9726d450..695c079f3f 100644
--- a/crates/ui-egui/src/chrome.rs
+++ b/crates/ui-egui/src/chrome.rs
@@ -937,10 +937,14 @@ pub fn shortcuts(app: &mut RustGisApp, ctx: &egui::Context) {
             {
                 continue;
             }
+            // The press that the shortcut takes, if it isn't only a held key's repeats, and the
+            // pane that was in use as it came.
+            let press = crate::inuse::press(app, b.chord.key, Some(b.chord.modifiers()));
+            let key_pane = press.map_or(pane, |press| press.pane);
             // Select All is the text's while a text field has the focus, and is left alone where
             // there are no features to select: in a layout, in ModelBuilder and in a standalone
             // table's view.
-            if b.command == "select.all" && select_all_left_alone(app, pane, typing || text_field) {
+            if b.command == "select.all" && select_all_left_alone(app, key_pane, typing || text_field) {
                 continue;
             }
             // Duplicating needs a selected layout element, and not a text field being typed in;
@@ -953,8 +957,6 @@ pub fn shortcuts(app: &mut RustGisApp, ctx: &egui::Context) {
             if element && !b.chord.command && matches!(b.chord.key, Key::ArrowLeft | Key::ArrowRight | Key::ArrowUp | Key::ArrowDown) {
                 continue;
             }
-            // The press that the shortcut takes, if it isn't only a held key's repeats.
-            let press = crate::inuse::press(app, b.chord.key, Some(b.chord.modifiers()));
             if i.consume_shortcut(&KeyboardShortcut::new(b.chord.modifiers(), b.chord.key)) {
                 let (id, params) = (b.command.clone(), b.params.clone());
                 match press {
@@ -1001,7 +1003,7 @@ pub fn shortcuts(app: &mut RustGisApp, ctx: &egui::Context) {
             // Clipboard keys arrive as events, not key presses. In the layer list they act on the
             // layers a click picks, so one that came while a click was under way waits for the
             // click to be taken, as Delete does.
-            let mut nth = 0;
+            let (mut nth, mut waits) = (0, false);
             for e in &i.events {
                 let (id, params) = match e {
                     egui::Event::Copy => ("ui.copy", Value::Null),
@@ -1011,7 +1013,9 @@ pub fn shortcuts(app: &mut RustGisApp, ctx: &egui::Context) {
                 };
                 let (key_pane, after_click) = crate::inuse::clipboard(app, nth).unwrap_or((pane, false));
                 nth += 1;
-                if key_pane == Pane::Layers && after_click {
+                // Once one waits, those after it wait too, so they run in the order they came.
+                waits |= key_pane == Pane::Layers && after_click;
+                if waits {
                     late.push(Late { id: id.into(), params, pane: key_pane, chord: None });
                 } else {
                     run.push((id.into(), params, key_pane));
diff --git a/crates/ui-egui/src/inuse.rs b/crates/ui-egui/src/inuse.rs
index 0d326c546f..f09b2a61bd 100644
--- a/crates/ui-egui/src/inuse.rs
+++ b/crates/ui-egui/src/inuse.rs
@@ -679,6 +679,11 @@ mod tests {
         // Text copied elsewhere since: the layers aren't the last thing copied any more.
         clip(&mut h, Event::Paste("something else".into()));
         assert_eq!(layer_names(&h), before, "a stale copy of layers isn't pasted");
+        // Another layer copied by a script since: the clipboard still names Rivers, which isn't
+        // what a paste would add.
+        h.state_mut().run("layer.copy", json!({"layer": "Cities"})).unwrap();
+        clip(&mut h, Event::Paste("Rivers".into()));
+        assert_eq!(layer_names(&h), before, "the clipboard names other layers than the ones copied");
 
         // Features copied since: Paste in the list adds them, not the layer copied before.
         let features = h.state_mut().run("edit.copy", Value::Null).unwrap()["text"].as_str().unwrap().to_string();
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index cff6c1c24f..8966523c7b 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1189,9 +1189,6 @@ pub struct UiState {
     pub dynamic_text: Option<&'static str>,
     /// Text to put on the system clipboard at the end of the frame.
     pub copy_out: Option,
-    /// The text the last copy of layers put on the clipboard (their names): while the clipboard
-    /// still holds it, a Paste key in the layer list pastes those layers.
-    pub(crate) layers_copied_as: Option,
     /// A web page to open at the end of the frame.
     pub open_url: Option,
     /// An image to put on the system clipboard at the end of the frame.
@@ -1284,7 +1281,6 @@ impl Default for UiState {
             pane_rects: [None; 2],
             in_use: inuse::InUse::default(),
             copy_out: None,
-            layers_copied_as: None,
             open_url: None,
             copy_image: None,
             pending_picture: None,
diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs
index ad7aafacf8..5e43f3ef03 100644
--- a/crates/ui-egui/src/panes.rs
+++ b/crates/ui-egui/src/panes.rs
@@ -966,24 +966,26 @@ fn paste_label(app: &RustGisApp) -> &'static str {
 /// Copies layers (`layer.copy` with `params`) and puts their names on the clipboard as text, one a
 /// line: a paste elsewhere gives the names, and a Paste key in the layer list can tell whether the
 /// layers are still the last thing copied ([`pastes_copied_layers`]). A copy with no layer in it
-/// (an empty group) leaves the clipboard alone. Whether they were copied.
-pub(crate) fn copy_layers(app: &mut RustGisApp, params: Value) -> bool {
-    let Ok(copied) = app.run("layer.copy", params) else { return false };
+/// (an empty group) puts no text there, so the Paste key doesn't take it; the menu's Paste does.
+/// A copy refused is said by `run`.
+pub(crate) fn copy_layers(app: &mut RustGisApp, params: Value) {
+    let Ok(copied) = app.run("layer.copy", params) else { return };
     let names: Vec<&str> = copied["layers"].as_array().into_iter().flatten().filter_map(Value::as_str).collect();
-    let names = names.join("\n");
-    app.ui.layers_copied_as = (!names.trim().is_empty()).then(|| names.clone());
-    if app.ui.layers_copied_as.is_some() {
-        app.ui.copy_out = Some(names);
+    if !names.is_empty() {
+        app.ui.copy_out = Some(names.join("\n"));
     }
-    true
 }
 
 /// Whether a Paste key in the layer list, with `text` on the clipboard, pastes the copied layers:
-/// while the clipboard still holds what the last copy of layers put there (line ends aside, which
-/// a clipboard may change). Features or text copied since are the newer copy.
+/// while the clipboard holds the names of the layers copied (line ends aside, which a clipboard
+/// may change). Features or text copied since are the newer copy, and layers a script copied
+/// since aren't the ones the clipboard names.
 pub(crate) fn pastes_copied_layers(app: &RustGisApp, text: &str) -> bool {
-    let lines = |text: &str| text.lines().map(str::trim_end).filter(|line| !line.is_empty()).map(str::to_owned).collect::>();
-    app.session.layer_clipboard.is_some() && app.ui.layers_copied_as.as_deref().is_some_and(|names| lines(names) == lines(text))
+    let pasted: Vec<&str> = text.lines().map(str::trim_end).filter(|line| !line.is_empty()).collect();
+    app.session
+        .layer_clipboard
+        .as_ref()
+        .is_some_and(|copy| !copy.layers.is_empty() && copy.layers.iter().map(|l| l.name.trim_end()).eq(pasted.iter().copied()))
 }
 
 /// Where `layer.paste` puts the copies when they are pasted on layer `id`: above it, or at the

From 863d5f2d2e2add4997f8ad4865439fa7ab3a8a5b Mon Sep 17 00:00:00 2001
From: mavrick 
Date: Fri, 27 Nov 2026 01:58:44 -0600
Subject: [PATCH 3/3] fix(ui): a copied group with no layer goes by its name on
 the clipboard

Copy Group on an empty group put no text on the clipboard, so features
copied before it stayed there and were what Paste in the layer list
took. The copy now goes by the group's name, as a copy of layers goes by
theirs, and Paste compares the clipboard with those names line by line,
so a name with a line break in it matches too.
---
 crates/ui-egui/src/inuse.rs | 11 ++++++++++
 crates/ui-egui/src/panes.rs | 41 +++++++++++++++++++++++--------------
 2 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/crates/ui-egui/src/inuse.rs b/crates/ui-egui/src/inuse.rs
index f09b2a61bd..f6189780a7 100644
--- a/crates/ui-egui/src/inuse.rs
+++ b/crates/ui-egui/src/inuse.rs
@@ -708,6 +708,17 @@ mod tests {
             h.state().map.toasts.iter().map(|t| &t.text).collect::>()
         );
 
+        // A group with no layer in it, copied from its menu: it goes by its own name, so the
+        // feature copied before it isn't what Paste takes.
+        h.state_mut().run("group.add", json!({"name": "Empty"})).unwrap();
+        let groups = |h: &Window| h.state().session.map().groups.len();
+        let n = groups(&h);
+        crate::panes::copy_layers(h.state_mut(), json!({"group": "Empty"}));
+        assert_eq!(h.state().ui.copy_out.as_deref(), Some("Empty"));
+        h.run_steps(2);
+        clip(&mut h, Event::Paste("Empty".into()));
+        assert_eq!(groups(&h), n + 1, "the copied group is pasted");
+
         // A layer clicked and Copy in one frame: the layer just clicked is the one copied.
         let lakes = h.get_by_label("Lakes").rect().center();
         in_one_frame(&mut h, [Event::PointerMoved(lakes), button(lakes, true), button(lakes, false), Event::Copy]);
diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs
index 5e43f3ef03..1d3e9d1224 100644
--- a/crates/ui-egui/src/panes.rs
+++ b/crates/ui-egui/src/panes.rs
@@ -963,29 +963,40 @@ fn paste_label(app: &RustGisApp) -> &'static str {
     }
 }
 
+/// The names a copy of layers goes by on the clipboard: its layers', or its groups' when it has no
+/// layer (an empty group was copied).
+fn copied_names(copy: &rustgis_engine::cmd::layer_copy::LayerClip) -> Vec<&str> {
+    if copy.layers.is_empty() {
+        copy.groups.iter().map(|g| g.name.as_str()).collect()
+    } else {
+        copy.layers.iter().map(|l| l.name.as_str()).collect()
+    }
+}
+
 /// Copies layers (`layer.copy` with `params`) and puts their names on the clipboard as text, one a
 /// line: a paste elsewhere gives the names, and a Paste key in the layer list can tell whether the
-/// layers are still the last thing copied ([`pastes_copied_layers`]). A copy with no layer in it
-/// (an empty group) puts no text there, so the Paste key doesn't take it; the menu's Paste does.
-/// A copy refused is said by `run`.
+/// layers are still the last thing copied ([`pastes_copied_layers`]). So what the clipboard held
+/// before (features, say) is replaced, as any copy replaces it. A copy refused is said by `run`.
 pub(crate) fn copy_layers(app: &mut RustGisApp, params: Value) {
-    let Ok(copied) = app.run("layer.copy", params) else { return };
-    let names: Vec<&str> = copied["layers"].as_array().into_iter().flatten().filter_map(Value::as_str).collect();
-    if !names.is_empty() {
-        app.ui.copy_out = Some(names.join("\n"));
+    if app.run("layer.copy", params).is_err() {
+        return;
+    }
+    let names = app.session.layer_clipboard.as_ref().map(copied_names).unwrap_or_default().join("\n");
+    if !names.trim().is_empty() {
+        app.ui.copy_out = Some(names);
     }
 }
 
 /// Whether a Paste key in the layer list, with `text` on the clipboard, pastes the copied layers:
-/// while the clipboard holds the names of the layers copied (line ends aside, which a clipboard
-/// may change). Features or text copied since are the newer copy, and layers a script copied
-/// since aren't the ones the clipboard names.
+/// while the clipboard holds the names the copy goes by ([`copied_names`]; line ends aside, which
+/// a clipboard may change). Features or text copied since are the newer copy, and layers a script
+/// copied since aren't the ones the clipboard names.
 pub(crate) fn pastes_copied_layers(app: &RustGisApp, text: &str) -> bool {
-    let pasted: Vec<&str> = text.lines().map(str::trim_end).filter(|line| !line.is_empty()).collect();
-    app.session
-        .layer_clipboard
-        .as_ref()
-        .is_some_and(|copy| !copy.layers.is_empty() && copy.layers.iter().map(|l| l.name.trim_end()).eq(pasted.iter().copied()))
+    let lines = |text: &str| text.lines().map(str::trim_end).filter(|line| !line.is_empty()).map(str::to_owned).collect::>();
+    app.session.layer_clipboard.as_ref().is_some_and(|copy| {
+        let names = lines(&copied_names(copy).join("\n"));
+        !names.is_empty() && names == lines(text)
+    })
 }
 
 /// Where `layer.paste` puts the copies when they are pasted on layer `id`: above it, or at the