diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 64d4fec82e..695c079f3f 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -937,6 +937,16 @@ 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, key_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) { @@ -947,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 { @@ -992,13 +1000,25 @@ 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, mut waits) = (0, false); 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; + // 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)); } } } @@ -1063,12 +1083,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 +1109,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 +1177,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 +1233,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 +1283,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..f6189780a7 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,157 @@ 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");
+        // 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();
+        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 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]);
+        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/panes.rs b/crates/ui-egui/src/panes.rs
index d1698c553e..1d3e9d1224 100644
--- a/crates/ui-egui/src/panes.rs
+++ b/crates/ui-egui/src/panes.rs
@@ -963,6 +963,52 @@ 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`]). 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) {
+    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 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 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
+/// 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 +1457,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 +2613,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.