diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rs index 52bdfe7aed..c7dcf16a0a 100644 --- a/crates/ui-egui/src/commands.rs +++ b/crates/ui-egui/src/commands.rs @@ -298,6 +298,19 @@ impl PdfCraftApp { } fn execute_unguarded(&mut self, ctx: &egui::Context, id: &str) -> bool { + // Paste is the framework's clipboard command, not a registered one: the pages take what + // the clipboard holds (pages in Organize, else objects, a picture or comment text). + if id == crate::menus::PASTE { + let Some(i) = self.active.filter(|&i| i < self.views.len()) else { return false }; + if self.views[i].organize { + return self.execute_unguarded(ctx, "page.paste"); + } + if self.views[i].session.forms.focus.is_some() { + return false; + } + self.paste_from_clipboard(ctx, i); + return true; + } let Some(spec) = commands::command(id) else { return false }; if !self.command_enabled(spec) { let why = self.disabled_reason(spec); diff --git a/crates/ui-egui/src/panels/side_panels.rs b/crates/ui-egui/src/panels/side_panels.rs index 52f2f0a7c9..26cce3cf7a 100644 --- a/crates/ui-egui/src/panels/side_panels.rs +++ b/crates/ui-egui/src/panels/side_panels.rs @@ -5,7 +5,9 @@ //! by earlier versions (`side_panels`, `docking`) are read once by [`migrate`]. use craft::automation::dock as dock_rpc; -use craft::behavior::dock::{Action, Column, DockEdge, DockPlacement, Group, Layout, Location, Node, Permissions, SplitSize, Target, Workspace}; +use craft::behavior::dock::{ + Action, Column, DockEdge, DockPlacement, Group, Layout, Location, Node, PanelState, Permissions, SplitSize, Target, Workspace, +}; use craft::behavior::{Axis, DockSide, IconId}; use craft::keymap::CommandRef; use craft::ui::buttons::IconButton; @@ -210,7 +212,10 @@ fn edge_name(edge: Option) -> &'static str { /// The side panel that is open, if any. fn open_side(workspace: &Workspace) -> Option { - SIDE.into_iter().find(|panel| workspace.layout.contains(panel)) + // The side panels share a group: the open one is its front tab. A minimized or collapsed group + // shows none in front, and then the first one open stands for it. + let layout = &workspace.layout; + SIDE.into_iter().find(|panel| layout.panel_state(panel) == PanelState::Front).or_else(|| SIDE.into_iter().find(|panel| layout.contains(panel))) } /// The tab label of a side panel: its name, and the count of what it lists where it has one. @@ -441,7 +446,7 @@ fn show_panel(app: &mut PdfCraftApp, panel: PanelId, visible: bool) -> Result<() /// The side panel `workspace` has open, `None` when every side panel is closed. pub(crate) fn right_of(workspace: &Workspace) -> Option { - SIDE.iter().find(|panel| workspace.layout.contains(panel)).and_then(|panel| panel.side()) + open_side(workspace).and_then(PanelId::side) } /// Opens or closes `panel`, telling the user when the dock refuses. diff --git a/crates/ui-egui/tests/it/ui.rs b/crates/ui-egui/tests/it/ui.rs index 2565445bd7..3bd0e3974e 100644 --- a/crates/ui-egui/tests/it/ui.rs +++ b/crates/ui-egui/tests/it/ui.rs @@ -50,7 +50,8 @@ fn side(h: &mut Harness<'static, PdfCraftApp>, key: &str) -> String { /// The side panel the workspace has open, as `ui.state` reports it (`side_panel`). pub(crate) fn right(app: &PdfCraftApp) -> Option { - use pdfcraft_ui_egui::side_panels::PanelId; + let state = pdfcraft_ui_egui::side_panels::state(app); + let open = state["side_panel"].as_str()?; [ RightPanel::Comments, RightPanel::Bookmarks, @@ -65,7 +66,7 @@ pub(crate) fn right(app: &PdfCraftApp) -> Option { RightPanel::Compare, ] .into_iter() - .find(|panel| app.dock.layout.contains(&PanelId::from(*panel))) + .find(|panel| format!("{panel:?}") == open) } /// Runs the command `id` as the app's own command entry does, with the harness's context.