Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Reconcile Pages sidebar selection with current keyboard and panel modules

FredAppsea66a642fee5
diff --cc ROADMAP.md
index 420bb2bcb,f5de8044e..7b371cf1b
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -530,3 -734,17 +734,21 @@@ Newest first: the date, what moved, an
- **2026-10-12 (M8):** Redaction cleans indirect and form structure references, preserving surviving form tags.
- **2026-10-13 (M7):** Edit a PDF ▸ Add content: Header and footer, Watermark and Background open an Add / Update / Remove menu (Update and Remove enabled only when the document has that mark), as Acrobat's Watermark control does. The catalogue gains `ToolItem::actions`, so any tool can list more commands (#1192).
+
+ - **2026-10-18 (M8, #1350):** Published the history-preserving integration; simplified the inherited-form resource guard for Rust 1.96 Clippy. Formatting, 64 redaction tests, scoped Clippy, layering, assets and the scoped wasm check pass locally. CI remains pending; estimates unchanged.
+
+ - 2026-10-18: M11 / #3227: mark target-version compatibility partial; document the unchecked newer-content limitation.
+
+ - **2026-10-18 (PR #3227 integration):** M11: integrate upstream b0e5c6eb; retain partial target-version compatibility claims and effective-version reporting, correcting the borrowed version parser lifetime. Scope and estimates unchanged.
+
+ - **2026-10-12 (i18n):** Albanian (`sq`, Shqip) added: 2,343-entry catalog, month and weekday names, Preferences entry; not yet reviewed by a native speaker.
+
+ - **2026-10-21 (M4, #3865):** A new bookmark records where the reader is: the top-left of the selected text, or the top of the window, as `/XYZ left top null` (zoom kept), instead of the page top (`Edit::AddBookmark` takes `left` and `top`; `bookmark_add` takes `top` and `left`; `PageInfo::xyz_for_view`).
+
+ - **2026-10-18 (renderer, hayro patches 19/35):** A mesh shading (types 4–7) is sampled over its own triangles instead of the whole path: a BricsCAD plan with 310 one-triangle `sh` fills took 2 s per 1024 px tile at every zoom (and hit the 20 s watchdog on a busy machine); now about 70 ms, so zooming into dense topology drawings stays fluid. Estimates unchanged.
+
+ - **2026-10-22 (PR #3227 integration):** M11: integrate upstream `80b7d215`; retain partial target-version compatibility and upstream content-boundary and image-size regression coverage. Scope and estimates unchanged.
++
++## Pages sidebar keyboard refresh (2026-10-30)
++
++PR #2133 retains document-local Pages sidebar focus for Ctrl/Cmd+A and Escape after the UI module split. The selection does not navigate. The focused regression is in `crates/ui-egui/tests/it/view.rs`; current-head hosted validation is pending. Feature counts and estimates are unchanged.
diff --cc crates/ui-egui/src/app/keys.rs
index 000000000,cdc696f95..6021af64d
mode 000000,100644..100644
--- a/crates/ui-egui/src/app/keys.rs
+++ b/crates/ui-egui/src/app/keys.rs
@@@ -1,0 -1,116 +1,120 @@@
+ use super::*;
+
+ impl PdfCraftApp {
+ pub(super) fn shortcuts(&mut self, ctx: &egui::Context) {
+ use egui::Key;
+ let pasted = self.paste_key_released(ctx);
+ // "Save changes?" is modal: its keys are its own (⌘D is Don't save there, not Document
+ // properties; Escape cancels it rather than clearing a selection), and nothing may run
+ // underneath it. They are read here, before the canvas can consume them.
+ if self.close_request.is_some() {
+ // These dialogs are drawn after the save prompt and own the keyboard while open.
+ // Don't let Escape or Return resolve unsaved work underneath one.
+ let covered = self.pending_link.is_some()
+ || self.pending_remote_link.is_some()
+ || self.pending_full_screen.is_some()
+ || self.updates.open
+ || self.dialog.is_some()
+ || self.unlock_prompt.is_some();
+ if !covered && let Some(choice) = dialogs::save_prompt_key(ctx, &mut self.save_prompt_button) {
+ self.resolve_close(ctx, choice);
+ }
+ return;
+ }
+ // The other dialogs and prompts are modal too (⌘W closed the file behind Preferences,
+ // #870).
+ if self.modal_open() {
+ return;
+ }
+ if let Some(view) = self.active.and_then(|i| self.views.get_mut(i))
+ && view.auto_scroll.escape(ctx)
+ {
+ return;
+ }
+ // The in-window menu bar holds the keys while one of its menus is open or it has the
+ // keyboard (Alt, F10); a command shortcut leaves it and runs.
+ craft_menu::bar::leave_for_shortcut(ctx);
+ if !craft_menu::bar::is_open(ctx) && !craft_menu::bar::is_focused(ctx) {
+ self.registry_shortcuts(ctx);
+ }
+ // (Esc closes a Combine file shown large first.)
+ if self.full_screen && self.combine_tab.preview.is_none() && ctx.input(|i| i.key_pressed(Key::Escape)) {
+ self.set_full_screen(ctx, false);
+ }
+ if let Some(i) = self.active {
+ // Select all belongs to the document or page grid, unless a text field or
+ // overlay owns the keyboard. Other canvas shortcuts keep their own handling.
++ let pages_owns_keyboard =
++ self.right == Some(RightPanel::Pages) && self.views[i].pages_focus_id.is_some_and(|id| ctx.memory(|m| m.has_focus(id)));
+ if self.dialog.is_none()
+ && !self.palette_open
- && !ctx.egui_wants_keyboard_input()
++ && (pages_owns_keyboard || !ctx.egui_wants_keyboard_input())
+ && ctx.input_mut(|input| input.consume_shortcut(&egui::KeyboardShortcut::new(egui::Modifiers::COMMAND, Key::A)))
+ {
- if self.is_preparing() {
++ if pages_owns_keyboard {
++ self.views[i].select_all_pages();
++ } else if self.is_preparing() {
+ if let Some(doc) = self.session.get(self.views[i].id) {
+ prepare::select_all(&mut self.views[i], &doc.form);
+ }
+ } else {
+ self.views[i].select_all();
+ }
+ }
+ self.tool_keys(i, ctx);
+ if self.quick_tool == QuickTool::EditText
+ && let Some(doc) = self.session.get(self.views[i].id).filter(|d| d.allows_modification())
+ {
+ object_ui::nudge_keys(ctx, &mut self.views[i], doc);
+ object_ui::delete_keys(ctx, &mut self.views[i]);
+ } else if let Some(doc) = self.session.get(self.views[i].id).filter(|d| d.allows_annotation()) {
+ comments::nudge_keys(ctx, &mut self.views[i], &doc.info);
+ }
+ // A selected field moves with the arrows too (Prepare a form, #2608), before the view
+ // turns the page with them.
+ if self.is_preparing()
+ && let Some(doc) = self.session.get(self.views[i].id).filter(|d| d.allows_modification())
+ {
+ prepare::nudge_keys(ctx, &mut self.views[i], doc);
+ }
+ canvas::shortcuts(&mut self.views[i], ctx, self.scroll_speed);
+ self.copy_key(i, ctx);
+ self.paste_image_key(i, ctx, pasted);
+ self.image_pick_keys(i, ctx);
+ }
+ }
+ }
+
+ impl PdfCraftApp {
+ /// The quick tools' keys, as in Acrobat: V selects, H pans, and holding Space pans until it
+ /// is released. Plain letters, so not while a text field, a form field, a dialog or the
+ /// palette has the keyboard.
+ fn tool_keys(&mut self, i: usize, ctx: &egui::Context) {
+ use egui::Key;
+ let free = self.dialog.is_none() && !self.palette_open && !ctx.egui_wants_keyboard_input() && self.views[i].forms.focus.is_none();
+ let (plain, space) = ctx.input(|input| (input.modifiers.is_none(), input.key_down(Key::Space)));
+ if let Some(previous) = self.space_hand
+ && !space
+ {
+ self.space_hand = None;
+ if self.quick_tool == QuickTool::Hand {
+ self.quick_tool = previous;
+ }
+ }
+ if !free || !plain {
+ return;
+ }
+ if ctx.input(|input| input.key_pressed(Key::V)) {
+ self.quick_tool = QuickTool::Select;
+ self.space_hand = None;
+ }
+ if ctx.input(|input| input.key_pressed(Key::H)) {
+ self.quick_tool = QuickTool::Hand;
+ self.space_hand = None;
+ }
+ if space && self.space_hand.is_none() && self.quick_tool != QuickTool::Hand {
+ self.space_hand = Some(self.quick_tool);
+ self.quick_tool = QuickTool::Hand;
+ }
+ }
+ }
diff --cc crates/ui-egui/src/canvas/selection.rs
index 000000000,cfc5967bc..c2b0545df
mode 000000,100644..100644
--- a/crates/ui-egui/src/canvas/selection.rs
+++ b/crates/ui-egui/src/canvas/selection.rs
@@@ -1,0 -1,250 +1,254 @@@
+ use super::{Arc, DocInfo, DocView, Edit, HashMap, PageText, Pos2, Range, Rect, comments, pos2};
+
+ /// A text selection on one page.
+ #[derive(Clone, Copy, Debug, PartialEq)]
+ pub(super) struct Selection {
+ pub(super) page: usize,
+ pub(super) span: Span,
+ }
+
+ #[derive(Clone, Copy, Debug, PartialEq)]
+ pub(super) enum Span {
+ /// Reading order, between two glyph indices.
+ Run { anchor: usize, head: usize },
+ /// Column select (#740): the glyphs inside a rectangle in page view space, drawn from the
+ /// corner the drag started at (`rect[0..2]`) to the pointer (`rect[2..4]`).
+ Column { rect: [f32; 4] },
+ }
+
+ impl Selection {
+ pub(super) fn run(page: usize, anchor: usize, head: usize) -> Self {
+ Self { page, span: Span::Run { anchor, head } }
+ }
+
+ fn range(anchor: usize, head: usize) -> Range<usize> {
+ anchor.min(head)..anchor.max(head).saturating_add(1)
+ }
+
+ /// One rectangle per selected piece of a line, in view space (highlighting, markup quads).
+ pub(super) fn rects(&self, text: &PageText) -> Vec<[f32; 4]> {
+ match self.span {
+ Span::Run { anchor, head } => text.line_rects(Self::range(anchor, head)),
+ Span::Column { rect } => text.glyph_rects(&text.glyphs_in(rect)),
+ }
+ }
+
+ /// The selected text, as Copy puts it on the clipboard.
+ pub(super) fn text(&self, text: &PageText) -> String {
+ match self.span {
+ Span::Run { anchor, head } => text.text_of(Self::range(anchor, head)),
+ Span::Column { rect } => text.column_text(&text.glyphs_in(rect)),
+ }
+ }
+ }
+
+ /// The glyphs `clicks` quick clicks select around glyph `a`: two the word, three the line, more
+ /// the page.
+ pub(super) fn click_unit(text: &PageText, clicks: u32, a: usize) -> Option<(usize, usize)> {
+ match clicks {
+ 2 => text.word_at(a),
+ 3 => text.line_at(a),
+ _ => text.glyphs.len().checked_sub(1).map(|last| (0, last)),
+ }
+ }
+
+ impl DocView {
+ /// The text selection as markup quadrilaterals in user space: (page, quads).
+ pub(crate) fn selection_quads(&self, info: &DocInfo) -> Option<(usize, Vec<[f64; 8]>)> {
+ let s = self.selection?;
+ let text = self.texts.get(&s.page)?;
+ let page = info.pages.get(s.page)?;
+ let quads: Vec<[f64; 8]> = s.rects(text).into_iter().map(|r| page.view_rect_to_quad(r)).collect();
+ (!quads.is_empty()).then_some((s.page, quads))
+ }
+
+ pub(crate) fn clear_selection(&mut self) {
+ self.selection = None;
+ self.actions_dismissed = None;
+ }
+
+ /// Select text on `page` from glyph `from` to glyph `to` (tests and automation).
+ pub fn select_text(&mut self, page: usize, from: usize, to: usize) {
+ self.all_text = false;
+ self.selection = Some(Selection::run(page, from, to));
+ }
+
+ /// Screen position of the centre of glyph `glyph` on `page`, if that page is on screen and its
+ /// text layer is loaded (used by UI tests and automation to aim pointer input).
+ pub fn glyph_screen_pos(&self, page: usize, glyph: usize) -> Option<Pos2> {
+ let (_, xf) = self.screen_xforms.iter().find(|(p, _)| *p == page)?;
+ let g = self.texts.get(&page)?.glyphs.get(glyph)?;
+ Some(xf.view_rect(g.rect).center())
+ }
+
+ /// Selected text, if any (⌘C).
+ /// The selected text: of the pages read so far, after Select All of the document (Copy reads
+ /// the others, [`DocView::pages_without_text`]).
+ pub fn selected_text(&self) -> Option<String> {
+ if self.all_text {
+ return Some(self.whole_text(&HashMap::new())).filter(|x| !x.is_empty());
+ }
+ let s = self.selection?;
+ let t = self.texts.get(&s.page)?;
+ Some(s.text(t)).filter(|x| !x.is_empty())
+ }
+
- /// Select all: every page in Organize, or every word on the current page.
++ /// Select every page without navigating; shared by Organize and the Pages sidebar.
++ pub fn select_all_pages(&mut self) -> bool {
++ self.selected = (0..self.page_count).collect();
++ self.select_anchor = (self.page_count > 0).then_some(self.current);
++ !self.selected.is_empty()
++ }
++
++ /// Select all words on the current page, or every page in Organize.
+ pub fn select_all(&mut self) -> bool {
+ if self.organize {
- self.selected = (0..self.page_count).collect();
- // Keep the current page as the anchor for the next Shift-click.
- self.select_anchor = (self.page_count > 0).then_some(self.current);
- return !self.selected.is_empty();
++ return self.select_all_pages();
+ }
+ // Scrolling continuously, Select All takes the whole document's text (#2639); one page at
+ // a time, the page shown.
+ // Like the page's, true once some text is selected: the pages whose text isn't read yet are
+ // read when the selection is copied.
+ if self.continuous && self.page_count > 1 {
+ self.selection = None;
+ self.all_text = true;
+ return self.selected_text().is_some();
+ }
+ self.all_text = false;
+ let page = self.current;
+ let Some(t) = self.texts.get(&page) else { return false };
+ if t.glyphs.is_empty() {
+ return false;
+ }
+ self.selection = Some(Selection::run(page, 0, t.glyphs.len() - 1));
+ true
+ }
+
+ /// Pages whose text [`DocView::whole_text`] still needs: not read yet, nor failed.
+ pub(crate) fn pages_without_text(&self) -> Vec<usize> {
+ (0..self.page_count).filter(|p| !self.texts.contains_key(p) && !self.text_failed.contains(p)).collect()
+ }
+
+ /// The whole document's text in page order, one page after another on new lines, from the
+ /// pages' text read so far and `more` (pages read for this, keyed by page).
+ pub(crate) fn whole_text(&self, more: &HashMap<usize, Arc<PageText>>) -> String {
+ let mut out = String::new();
+ for p in 0..self.page_count {
+ let Some(t) = self.texts.get(&p).or_else(|| more.get(&p)) else { continue };
+ let text = t.text_of(0..t.glyphs.len());
+ if text.is_empty() {
+ continue;
+ }
+ if !out.is_empty() {
+ out.push('\n');
+ }
+ out.push_str(&text);
+ }
+ out
+ }
+ }
+
+ #[derive(Clone, Copy)]
+ enum SelectionAction {
+ Note,
+ Markup(comments::CommentTool),
+ Replace,
+ Copy,
+ }
+
+ /// Actions on an existing text selection, next to the selected words.
+ pub(super) fn selection_actions(
+ ui: &mut egui::Ui,
+ viewport: Rect,
+ view: &mut DocView,
+ info: &DocInfo,
+ prefs: &comments::CommentPrefs,
+ can_comment: bool,
+ can_copy: bool,
+ ) -> bool {
+ if ui.input(|input| input.pointer.is_decidedly_dragging()) {
+ return false;
+ }
+ let Some(selection) = view.selection else {
+ view.actions_dismissed = None;
+ return false;
+ };
+ if view.actions_dismissed == Some(selection) {
+ return false;
+ }
+ let Some(text) = view.texts.get(&selection.page) else { return false };
+ let Some(xf) = view.page_xform(selection.page) else { return false };
+ let Some(last) = selection.rects(text).last().copied() else { return false };
+ let selected = selection.text(text);
+ if selected.is_empty() {
+ return false;
+ }
+ let rect = xf.view_rect(last);
+ if !viewport.intersects(rect) {
+ return false;
+ }
+ let x = rect.left().clamp(viewport.left() + 8.0, (viewport.right() - 520.0).max(viewport.left() + 8.0));
+ let y = if rect.bottom() + 48.0 < viewport.bottom() { rect.bottom() + 6.0 } else { (rect.top() - 44.0).max(viewport.top() + 6.0) };
+ let mut chosen = None;
+ egui::Area::new(egui::Id::unique(("text-selection-actions", view.id.0))).order(egui::Order::Foreground).fixed_pos(pos2(x, y)).show(
+ ui.ctx(),
+ |ui| {
+ egui::Frame::popup(ui.style()).show(ui, |ui| {
+ ui.horizontal(|ui| {
+ for (label, action) in [
+ (tl!("Add comment"), SelectionAction::Note),
+ (tl!("Highlight"), SelectionAction::Markup(comments::CommentTool::Highlight)),
+ (tl!("Underline"), SelectionAction::Markup(comments::CommentTool::Underline)),
+ (tl!("Strikethrough"), SelectionAction::Markup(comments::CommentTool::StrikeOut)),
+ (tl!("Replace text"), SelectionAction::Replace),
+ ] {
+ if ui.add_enabled(can_comment, egui::Button::new(label)).clicked() {
+ chosen = Some(action);
+ }
+ }
+ if ui.add_enabled(can_copy, egui::Button::new(tl!("Copy"))).clicked() {
+ chosen = Some(SelectionAction::Copy);
+ }
+ });
+ });
+ },
+ );
+ let Some(action) = chosen else { return false };
+ if let SelectionAction::Copy = action {
+ // Copying closes the bar but keeps the words selected, for ⌘C or a second action.
+ view.actions_dismissed = Some(selection);
+ return true;
+ }
+ let Some((page, quads)) = view.selection_quads(info) else { return false };
+ let last = quads.last().copied().unwrap_or_default();
+ let at = [last[2].max(last[6]), last[1].max(last[3])];
+ view.clear_selection();
+ match action {
+ SelectionAction::Note | SelectionAction::Replace => {
+ if matches!(action, SelectionAction::Replace) {
+ view.comments.replace = Some(quads);
+ }
+ view.comments.composer = Some(comments::Composer {
+ page,
+ at,
+ kind: if matches!(action, SelectionAction::Replace) { comments::ComposerKind::Replace } else { comments::ComposerKind::Note },
+ text: String::new(),
+ focus: true,
+ });
+ }
+ SelectionAction::Markup(tool) => {
+ // Every markup button carries a markup tool; anything else adds nothing.
+ let Some(kind) = tool.markup() else { return false };
+ view.pending_edit = Some(Edit::AddAnnotation(pdfcraft_engine::NewAnnotation {
+ page,
+ shape: pdfcraft_engine::Shape::TextMarkup { kind, quads },
+ style: prefs.style(tool),
+ contents: String::new(),
+ author: prefs.author.clone(),
+ }));
+ }
+ // Copy is dispatched through the app after the view borrow ends.
+ SelectionAction::Copy => {}
+ }
+ false
+ }
diff --cc crates/ui-egui/src/panels/pages.rs
index 000000000,1157b64a4..cda3cb5ec
mode 000000,100644..100644
--- a/crates/ui-egui/src/panels/pages.rs
+++ b/crates/ui-egui/src/panels/pages.rs
@@@ -1,0 -1,359 +1,366 @@@
+ use super::{Align, Align2, Color32, CornerRadius, DocInfo, Layout, Nav, Rect, Sense, Stroke, Tokens, icons, pos2, theme, vec2};
+
+ /// Page tools in the Pages panel's header (#4415): a menu, as Bookmark options is in its panel,
+ /// to insert a blank page or pages from a file, rotate, extract and delete. Each runs its
+ /// command on the selected pages (the current page when none is), so it does what Pages ▸ …
+ /// does; the items say so, apart from the thumbnails' own menu. `enabled` is false while the
+ /// document may not be assembled or a dialog is open. Returns the command a click asks for.
+ pub(super) fn page_tools(ui: &mut egui::Ui, enabled: bool) -> Option<&'static str> {
+ let tools: [(&'static str, &str); 6] = [
+ ("page.insert_blank", tl!("Insert a blank page after the selection")),
+ ("page.insert", tl!("Insert pages from a file after the selection…")),
+ ("page.rotate_ccw", tl!("Rotate the selected pages counterclockwise")),
+ ("page.rotate", tl!("Rotate the selected pages clockwise")),
+ ("page.extract", tl!("Extract the selected pages…")),
+ ("page.delete", tl!("Delete the selected pages")),
+ ];
+ let mut picked = None;
+ ui.add_enabled_ui(enabled, |ui| {
+ let more = icons::button(ui, "ellipsis", 26.0, false, tl!("Page tools"));
+ egui::Popup::menu(&more).show(|ui| {
+ ui.set_min_width(260.0);
+ for (id, label) in tools {
+ let Some(spec) = pdfcraft_engine::commands::command(id) else { continue };
+ let item = egui::Button::image_and_text(icons::image(spec.icon, 16.0, ui.visuals().text_color()), label);
+ if ui.add(item).clicked() {
+ picked = Some(id);
+ ui.close();
+ }
+ }
+ });
+ });
+ picked
+ }
+
+ /// Size controls stay above the scroll area, so they remain reachable on long documents.
+ pub(super) fn thumbnail_size(ui: &mut egui::Ui, t: &Tokens, view: &mut crate::DocView, enabled: bool) {
+ let before = view.thumbnail_zoom();
+ let mut zoom = before;
+ let label = ui
+ .horizontal(|ui| {
+ let label = ui.label(egui::RichText::new(tl!("Thumbnail size")).small().color(t.text_muted));
+ ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
+ ui.label(egui::RichText::new(format!("{:.0}%", before * 100.0)).small().color(t.text_muted));
+ });
+ label
+ })
+ .inner;
+ ui.add_enabled_ui(enabled, |ui| {
+ ui.spacing_mut().slider_width = (ui.available_width() - 52.0 - 2.0 * ui.spacing().item_spacing.x).max(1.0);
+ ui.horizontal(|ui| {
+ if ui
+ .add_enabled_ui(zoom > *crate::canvas::THUMBNAIL_ZOOM_RANGE.start(), |ui| {
+ icons::button(ui, "zoom-out", 26.0, false, tl!("Smaller thumbnails"))
+ })
+ .inner
+ .clicked()
+ {
+ zoom -= 0.25;
+ }
+ let mut percent = zoom * 100.0;
+ let range = (*crate::canvas::THUMBNAIL_ZOOM_RANGE.start() * 100.0)..=(*crate::canvas::THUMBNAIL_ZOOM_RANGE.end() * 100.0);
+ ui.scope(|ui| {
+ // The regular field fill blends into this panel; keep the slider's full rail visible.
+ ui.visuals_mut().widgets.inactive.bg_fill = t.border;
+ let slider = ui.add(egui::Slider::new(&mut percent, range).step_by(1.0).show_value(false).trailing_fill(true)).labelled_by(label.id);
+ slider.widget_info(|| egui::WidgetInfo::slider(ui.is_enabled(), f64::from(percent), tl!("Thumbnail size")));
+ });
+ zoom = percent / 100.0;
+ if ui
+ .add_enabled_ui(zoom < *crate::canvas::THUMBNAIL_ZOOM_RANGE.end(), |ui| {
+ icons::button(ui, "zoom-in", 26.0, false, tl!("Larger thumbnails"))
+ })
+ .inner
+ .clicked()
+ {
+ zoom += 0.25;
+ }
+ });
+ });
+ if zoom != before {
+ view.set_thumbnail_zoom(zoom);
+ }
+ ui.add_space(6.0);
+ }
+
+ /// The page thumbnails. A click goes to the page; ⌘/Ctrl-click and ⇧-click pick several pages
+ /// (the selection page commands and Print act on) without moving the document. Right-click
+ /// offers Extract, Cut, Copy and Paste on the selection, or on the page clicked; dragging
+ /// moves the selection, or the page grabbed, to the gap it is dropped on.
+ pub(super) fn pages(ui: &mut egui::Ui, t: &Tokens, info: &DocInfo, view: &mut crate::DocView, modal: bool, editable: bool, nav: &mut Option<Nav>) {
++ let focus_id = ui.make_persistent_id(("pages-keyboard", view.id));
++ view.pages_focus_id = Some(focus_id);
++ let keyboard = ui.interact(ui.clip_rect(), focus_id, Sense::focusable_noninteractive());
++ let owns_keyboard = keyboard.has_focus();
++ // Escape remains with the panel after the pointer moves away.
++ ui.memory_mut(|m| m.set_focus_lock_filter(focus_id, egui::EventFilter { escape: true, ..Default::default() }));
+ // Escape drops the selection while the pointer is over the panel and nothing else wants the key.
+ if !modal
+ && !view.selected.is_empty()
- && !ui.ctx().egui_wants_keyboard_input()
- && ui.rect_contains_pointer(ui.clip_rect())
++ && (owns_keyboard || !ui.ctx().egui_wants_keyboard_input())
++ && (owns_keyboard || ui.rect_contains_pointer(ui.clip_rect()))
+ && ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape))
+ {
+ view.clear_page_selection(Some(view.current));
+ }
+ // Delete (or Backspace) deletes the selection, or the current page, likewise.
+ if !modal
+ && editable
- && !ui.ctx().egui_wants_keyboard_input()
- && ui.rect_contains_pointer(ui.clip_rect())
++ && (owns_keyboard || !ui.ctx().egui_wants_keyboard_input())
++ && (owns_keyboard || ui.rect_contains_pointer(ui.clip_rect()))
+ && ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Delete) || i.consume_key(egui::Modifiers::NONE, egui::Key::Backspace))
+ {
+ delete_pages(view, info.pages.len());
+ }
+ // A new current page scrolls its thumbnail into view, as little as it takes (Acrobat), but
+ // not while thumbnails are dragged: then the change counts as seen. A wheel turned or a
+ // scroll bar dragged by the user already wins over a scroll to a place in egui.
+ let follow = view.panel_followed != Some(view.current) && view.panel_drag.is_none();
+ view.panel_followed = Some(view.current);
+ let available = (ui.available_width() - 16.0).max(1.0);
+ let usual = (ui.available_width() - 40.0).clamp(1.0, 150.0);
+ let w = (usual * view.thumbnail_zoom()).min(available);
+ let count = info.pages.len();
+ let mut rows: Vec<Rect> = Vec::with_capacity(info.pages.len());
+ let mut dropped = false;
+ for (i, p) in info.pages.iter().enumerate() {
+ ui.vertical_centered(|ui| {
+ let h = w * p.height / p.width.max(1.0);
+ let sense = if editable { Sense::click_and_drag() } else { Sense::click() };
+ let (rect, resp) = ui.allocate_exact_size(vec2(w + 16.0, h + 16.0), sense);
+ rows.push(rect);
+ if rect.intersects(ui.clip_rect().expand(200.0)) {
+ view.need_thumbnail(i, rect.intersects(ui.clip_rect()));
+ }
+ // Only the primary button drags pages (the middle button scrolls, the secondary one opens the menu).
+ if resp.drag_started_by(egui::PointerButton::Primary) {
+ if !view.target_pages().contains(&i) {
+ view.click_page(i, egui::Modifiers::NONE, true);
+ }
+ view.panel_drag = Some(view.target_pages());
+ }
+ if resp.drag_stopped() {
+ dropped = true;
+ }
+ let info = crate::i18n::fmt(tl!("Page {label}"), &[("label", &p.label)]);
+ let picked = view.selected.contains(&i);
+ resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, picked, info.clone()));
+ // The current page keeps its heavier border; picked pages share its fill.
+ let selected = i == view.current;
+ let press = theme::Press::track(ui, &resp);
+ press.wash(ui, rect, 8, selected || picked);
+ if picked {
+ ui.painter().rect_stroke(rect, CornerRadius::same(8), Stroke::new(1.5, t.accent), egui::StrokeKind::Inside);
+ }
+ let pr = rect.translate(press.offset()).shrink(8.0);
+ ui.painter().rect_filled(pr, CornerRadius::ZERO, Color32::WHITE);
+ if let Some(tex) = view.thumb(i) {
+ ui.painter().image(tex.id(), pr, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE);
+ }
+ ui.painter().rect_stroke(
+ pr,
+ CornerRadius::ZERO,
+ Stroke::new(if selected { 2.0 } else { 1.0 }, if selected { t.accent } else { t.border }),
+ egui::StrokeKind::Outside,
+ );
+ let label = ui.label(egui::RichText::new(&p.label).font(theme::medium(12.0)).color(if selected || picked {
+ t.accent_text
+ } else {
+ t.text_muted
+ }));
+ if follow && selected {
+ ui.scroll_to_rect(rect.union(label.rect), None);
+ }
+ let resp = theme::hand(resp);
+ if resp.clicked() {
++ ui.memory_mut(|m| m.request_focus(focus_id));
+ let m = ui.input(|i| i.modifiers);
+ if m.shift || m.command {
+ view.click_page(i, m, true);
+ } else {
+ view.clear_page_selection(Some(i));
+ // A page clicked here is in view already: the panel stays put.
+ view.panel_followed = Some(i);
+ *nav = Some(Nav::Page(i));
+ }
+ }
+ resp.context_menu(|ui| {
+ // A page outside the selection becomes the selection, as in the organize grid.
+ if !view.target_pages().contains(&i) {
+ view.click_page(i, egui::Modifiers::NONE, true);
+ }
+ if ui.button(tl!("Extract pages")).clicked() {
+ view.pending_action = Some(crate::canvas::ViewAction::Extract);
+ ui.close();
+ }
+ if ui.button(tl!("Split document…")).clicked() {
+ if view.selected.is_empty() {
+ view.select_pages(&[i]);
+ }
+ view.pending_action = Some(crate::canvas::ViewAction::SplitBeforeSelected);
+ ui.close();
+ }
+ if ui.add_enabled(editable, egui::Button::new(tl!("Replace pages…"))).clicked() {
+ view.pending_action = Some(crate::canvas::ViewAction::ReplacePages);
+ ui.close();
+ }
+ ui.separator();
+ if ui.add_enabled(editable, egui::Button::new(tl!("Cut"))).clicked() {
+ view.pending_action = Some(crate::canvas::ViewAction::CopyPages { cut: true });
+ ui.close();
+ }
+ if ui.button(tl!("Copy")).clicked() {
+ view.pending_action = Some(crate::canvas::ViewAction::CopyPages { cut: false });
+ ui.close();
+ }
+ if ui.add_enabled(editable, egui::Button::new(tl!("Paste after"))).clicked() {
+ view.pending_action = Some(crate::canvas::ViewAction::PastePages);
+ ui.close();
+ }
+ ui.separator();
+ let some_left = view.target_pages().len() < count;
+ // Never every page: a document keeps at least one.
+ if ui.add_enabled(editable && some_left, egui::Button::new(tl!("Delete pages"))).clicked() {
+ delete_pages(view, count);
+ ui.close();
+ }
+ });
+ });
+ ui.add_space(4.0);
+ }
+ page_drag(ui, t, view, &rows, dropped);
+ file_drop(ui, t, view, &rows, editable && !modal);
+ }
+
+ /// Files dragged in from outside go to the gap under the pointer: remember where the panel is
+ /// and that gap, for the app to take the drop, and show where the pages would go.
+ fn file_drop(ui: &mut egui::Ui, t: &Tokens, view: &mut crate::DocView, rows: &[Rect], editable: bool) {
+ if !editable {
+ return;
+ }
+ let clip = ui.clip_rect();
+ view.pages_panel = Some(clip);
+ let pointer = ui.input(|i| i.pointer.hover_pos()).filter(|p| clip.contains(*p));
+ view.panel_gap = pointer.filter(|_| view.panel_drag.is_none()).and_then(|p| panel_gap(rows, p.y));
+ if pointer.is_none() || ui.input(|i| i.raw.hovered_files.is_empty()) {
+ return;
+ }
+ let painter = ui.painter().with_clip_rect(clip);
+ painter.rect_stroke(clip.shrink(2.0), CornerRadius::same(6), Stroke::new(2.0, t.accent), egui::StrokeKind::Inside);
+ if let (Some(gap), Some(first), Some(last)) = (view.panel_gap, rows.first(), rows.last()) {
+ let y = rows.get(gap).map_or(last.bottom() + 2.0, |r| r.top() - 3.0);
+ painter.line_segment([pos2(first.left(), y), pos2(first.right(), y)], Stroke::new(3.0, t.accent));
+ }
+ }
+
+ /// Queue deleting the selection (or the current page) of a document of `n` pages, unless that
+ /// would leave no page. The selection goes; the current page stays on the page it showed, or on
+ /// the page that follows the deleted ones.
+ fn delete_pages(view: &mut crate::DocView, n: usize) {
+ let mut pages = view.target_pages();
+ pages.sort_unstable();
+ pages.dedup();
+ if pages.is_empty() || pages.len() >= n {
+ return;
+ }
+ // Deleted pages before it shift it up; if it was deleted itself, the page after the deleted
+ // run lands where it was (or the last page, when the deletion ran to the end).
+ let before = pages.iter().filter(|p| **p < view.current).count();
+ view.current = view.current.saturating_sub(before).min(n.saturating_sub(pages.len() + 1));
+ view.clear_page_selection(None);
+ view.pending_edit = Some(pdfcraft_engine::Edit::DeletePages { pages });
+ }
+
+ /// The gap (0 = before the first page, n = after the last) the pointer points at in the Pages
+ /// panel, whose thumbnails are `rows`, top to bottom.
+ fn panel_gap(rows: &[Rect], y: f32) -> Option<usize> {
+ let (i, r) = rows.iter().enumerate().min_by(|(_, a), (_, b)| (a.center().y - y).abs().total_cmp(&(b.center().y - y).abs()))?;
+ Some(if y < r.center().y { i } else { i + 1 })
+ }
+
+ /// Where page `p` goes when `moving` (sorted) move to `to` (counted without them).
+ fn moved_index(p: usize, moving: &[usize], to: usize) -> usize {
+ match moving.iter().position(|m| *m == p) {
+ Some(k) => to + k,
+ None => {
+ let rest = p.saturating_sub(moving.iter().filter(|m| **m < p).count());
+ if rest >= to { rest + moving.len() } else { rest }
+ }
+ }
+ }
+
+ /// While thumbnails are dragged: a bar on the gap they would go to, the page count by the
+ /// pointer, and scrolling near the panel's edges. On release, queue the move.
+ fn page_drag(ui: &mut egui::Ui, t: &Tokens, view: &mut crate::DocView, rows: &[Rect], dropped: bool) {
+ let Some(mut moving) = view.panel_drag.clone() else { return };
+ // A drag that ended while the panel was closed (or elsewhere) leaves nothing to drop.
+ if !dropped && !ui.input(|i| i.pointer.primary_down()) {
+ view.panel_drag = None;
+ return;
+ }
+ let pointer = ui.input(|i| i.pointer.interact_pos());
+ let gap = pointer.and_then(|p| panel_gap(rows, p.y));
+ if let (Some(gap), Some(first), Some(last)) = (gap, rows.first(), rows.last()) {
+ let y = rows.get(gap).map_or(last.bottom() + 20.0, |r| r.top() - 3.0);
+ ui.painter().line_segment([pos2(first.left(), y), pos2(first.right(), y)], Stroke::new(3.0, t.accent));
+ }
+ if let Some(p) = pointer {
+ let n = moving.len();
+ let what = if n == 1 { tl!("1 page").to_string() } else { crate::i18n::fmt(tl!("{n} pages"), &[("n", &n.to_string())]) };
+ ui.painter().text(p + vec2(14.0, 14.0), Align2::LEFT_TOP, what, theme::medium(12.0), t.accent_text);
+ let clip = ui.clip_rect();
+ let edge = 40.0;
+ if p.y < clip.top() + edge {
+ ui.scroll_with_delta(vec2(0.0, 10.0));
+ } else if p.y > clip.bottom() - edge {
+ ui.scroll_with_delta(vec2(0.0, -10.0));
+ }
+ ui.ctx().request_repaint();
+ }
+ if !dropped {
+ return;
+ }
+ view.panel_drag = None;
+ let Some(gap) = gap else { return };
+ moving.sort_unstable();
+ moving.dedup();
+ let Some(&first) = moving.first() else { return };
+ // `to` counts positions without the moving pages.
+ let to = gap.saturating_sub(moving.iter().filter(|x| **x < gap).count());
+ let contiguous = moving.windows(2).all(|w| w[1] == w[0] + 1);
+ if contiguous && to == first {
+ return;
+ }
+ view.current = moved_index(view.current, &moving, to);
+ view.selected = (to..to + moving.len()).collect();
+ view.pending_edit = Some(pdfcraft_engine::Edit::MovePages { pages: moving, to });
+ }
+
+ #[cfg(test)]
+ mod page_moves {
+ use super::{moved_index, panel_gap};
+ use egui::{Rect, pos2};
+
+ /// Above a thumbnail's middle is the gap before it; below is the gap after it.
+ #[test]
+ fn the_gap_follows_the_nearest_thumbnail() {
+ let rows: Vec<Rect> = (0..3).map(|i| Rect::from_min_max(pos2(0.0, i as f32 * 100.0), pos2(50.0, i as f32 * 100.0 + 90.0))).collect();
+ assert_eq!(panel_gap(&rows, -20.0), Some(0));
+ assert_eq!(panel_gap(&rows, 30.0), Some(0));
+ assert_eq!(panel_gap(&rows, 60.0), Some(1));
+ assert_eq!(panel_gap(&rows, 260.0), Some(3));
+ assert_eq!(panel_gap(&rows, 900.0), Some(3));
+ assert_eq!(panel_gap(&[], 10.0), None);
+ }
+
+ /// The current page follows a move, whether it moved or others moved around it.
+ #[test]
+ fn pages_keep_their_identity_across_a_move() {
+ // [0 1 2 3 4], move [1 2] to the end: [0 3 4 1 2].
+ let order: Vec<usize> = (0..5).map(|p| moved_index(p, &[1, 2], 3)).collect();
+ assert_eq!(order, [0, 3, 4, 1, 2]);
+ // Move [3] to the front: [3 0 1 2 4].
+ let order: Vec<usize> = (0..5).map(|p| moved_index(p, &[3], 0)).collect();
+ assert_eq!(order, [1, 2, 3, 0, 4]);
+ }
+ }
diff --cc docs/roadmap.md
index 608d5fead,25205e92c..c36e67c62
--- a/docs/roadmap.md
+++ b/docs/roadmap.md
@@@ -240,5 -353,7 +353,11 @@@ Estimates unchanged
| 2026-10-10 | minor | M3 records the System appearance completion after #881; estimates unchanged |
| 2026-10-10 | minor | Re-judged convert and share with the cross-app gate rule (only a workflow that can't be completed at all blocks): partial, not blocking → stage alpha |
| 2026-10-10 | minor | Added the alpha gate (six core workflows; convert and share fails → pre-alpha, 40–70 h to alpha) and rank 0 in the upcoming milestones |
+ | 2026-10-12 | minor | M8: cleanup removes replacement descriptions only from changed marked-content spans, preserving surviving accessibility text. Estimates unchanged. |
| 2026-10-12 | minor | M8: image redaction removes alternate images and unsupported masks only on affected images. Estimates unchanged. |
| 2026-10-10 | major | Created from ROADMAP.md §Milestones, §Critical path, §Risks and §Where we're lacking. Merged the duplicated M1, M2, M3 and M14 rows, re-measured Done and Remaining, added Current focus and the ranked upcoming milestones |
+ | 2026-10-18 | minor | #3227: M11: integrate upstream b0e5c6eb; retain partial target-version compatibility claims and effective-version reporting, correcting the borrowed version parser lifetime. Scope and estimates unchanged. |
++
++## Pages sidebar keyboard refresh (2026-10-30)
++
++PR #2133 retains document-local Pages sidebar focus for Ctrl/Cmd+A and Escape after the UI module split. The selection does not navigate. The focused regression is in `crates/ui-egui/tests/it/view.rs`; current-head hosted validation is pending. Feature counts and estimates are unchanged.
diff --cc parity/acrobat-features.toml
index f7316da98,3b8dba920..472a694f7
--- a/parity/acrobat-features.toml
+++ b/parity/acrobat-features.toml
@@@ -1274,8 -1286,8 +1286,8 @@@ milestone = "M4
status = "shipped"
commands = []
tools = []
- evidence = ["crates/ui-egui/tests/view.rs::pages_sidebar_select_all_keeps_current_page_and_keyboard_scope", "crates/ui-egui/tests/editing.rs::dragging_pages_panel_thumbnails_reorders_pages", "crates/ui-egui/tests/viewer.rs::pages_panel_thumbnails_have_a_context_menu", "crates/ui-egui/tests/editing.rs::deleting_pages_from_the_pages_panel_menu", "crates/ui-egui/tests/editing.rs::the_delete_key_deletes_pages_picked_in_the_pages_panel_but_never_every_page"]
- notes = "Ctrl/Cmd+A selects every page when the Pages sidebar owns the keyboard, without navigation; Escape clears the selection. Viewer and text-field shortcuts retain their own scope. Drag the selection (or the page grabbed) to reorder, with a drop bar and edge scrolling; right-click offers Extract pages, Cut, Copy, Paste after and Delete pages (also the Delete key over the panel). Not yet: Rotate, Insert and Page labels in the menu, dragging pages between documents, or dropping files onto the panel."
-evidence = ["crates/ui-egui/tests/it/editing.rs::dragging_pages_panel_thumbnails_reorders_pages", "crates/ui-egui/tests/it/viewer.rs::pages_panel_thumbnails_have_a_context_menu", "crates/ui-egui/tests/it/editing.rs::split_from_pages_panel_context_menu", "crates/ui-egui/tests/it/editing.rs::deleting_pages_from_the_pages_panel_menu", "crates/ui-egui/tests/it/editing.rs::the_delete_key_deletes_pages_picked_in_the_pages_panel_but_never_every_page"]
-notes = "Drag the selection (or the page grabbed) to reorder, with a drop bar and edge scrolling; right-click offers Split document…, Extract pages, Cut, Copy, Paste after and Delete pages (also the Delete key over the panel). Not yet: Rotate, Insert and Page labels in the menu, dragging pages between documents, or dropping files onto the panel."
++evidence = ["crates/ui-egui/tests/it/view.rs::pages_sidebar_select_all_keeps_current_page_and_keyboard_scope", "crates/ui-egui/tests/it/editing.rs::dragging_pages_panel_thumbnails_reorders_pages", "crates/ui-egui/tests/it/viewer.rs::pages_panel_thumbnails_have_a_context_menu", "crates/ui-egui/tests/it/editing.rs::split_from_pages_panel_context_menu", "crates/ui-egui/tests/it/editing.rs::deleting_pages_from_the_pages_panel_menu", "crates/ui-egui/tests/it/editing.rs::the_delete_key_deletes_pages_picked_in_the_pages_panel_but_never_every_page"]
++notes = "Ctrl/Cmd+A selects every page while the Pages sidebar owns the keyboard, without navigation; Escape clears that selection. Viewer and text-field shortcuts keep their own scope. Drag the selection (or the page grabbed) to reorder, with a drop bar and edge scrolling; right-click offers Split document…, Extract pages, Cut, Copy, Paste after and Delete pages (also the Delete key over the panel). Not yet: Rotate, Insert and Page labels in the menu, dragging pages between documents, or dropping files onto the panel."
[[feature]]
id = "view.bookmarks-panel"