PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
M4: a new bookmark goes to where the reader is (#3865)
Adrian946a77cf9b1d
diff --git a/ROADMAP.md b/ROADMAP.mdindex b1283e775..5dd13cf61 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -591,3 +591,5 @@ Newest first: the date, what moved, and the new overall estimate.- **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-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`).diff --git a/crates/automation/src/lib.rs b/crates/automation/src/lib.rsindex 0e2e0dd69..be2aebda0 100644--- a/crates/automation/src/lib.rs+++ b/crates/automation/src/lib.rs@@ -96,6 +96,9 @@ const WATERMARK_MAX_OFFSET: f64 = 20_000.0;/// Bookmarks in one page of the bookmark list, by default and at most.const BOOKMARK_PAGE: usize = 100;const MAX_BOOKMARK_PAGE: usize = 1000;+/// How far from the page's corner a bookmark's position may be given, in points (a PDF page is at+/// most 14 400 across).+const MAX_BOOKMARK_POSITION: f64 = 1_000_000.0;/// `text_find` extracts this many pages first, doubling each batch up to [`FIND_MAX_BATCH`], so a/// match near the start returns without touching the rest of a long document (#971).@@ -339,7 +342,13 @@ impl Automation {let parent = a.opt_path("parent")?.unwrap_or_default();let index = a.opt_int("position")?.map_or(usize::MAX, |p| (p.max(1) - 1) as usize);let title = a.str("title")?.to_string();- self.apply(&a, Edit::AddBookmark { parent, index, title, page })?+ let (left, top) = (a.bookmark_coordinate("left")?, a.bookmark_coordinate("top")?);+ let [left, top] = match self.doc(&a)?.info.pages.get(page) {+ Some(p) => p.xyz_for_view(left, top),+ None => [None, None],+ };+ let (left, top) = (left.map(f64::from), top.map(f64::from));+ self.apply(&a, Edit::AddBookmark { parent, index, title, page, left, top })?}"bookmark_rename" => {let (path, title) = (a.path("path")?, a.str("title")?.to_string());@@ -2287,6 +2296,15 @@ impl Args<'_> {let Some(v) = self.opt_ints(key)? else { return Ok(None) };v.iter().map(|i| if *i >= 1 { Ok(*i as usize - 1) } else { Err(Self::wrong(key, "1-based positions")) }).collect::<Result<Vec<_>>>().map(Some)}+ /// A bookmark's `left` or `top`: points on the displayed page, `None` when left out, an error+ /// when it is not a number or lies absurdly far off the page.+ fn bookmark_coordinate(&self, key: &str) -> Result<Option<f32>> {+ match self.opt_num(key)? {+ None => Ok(None),+ Some(v) if v.is_finite() && v.abs() <= MAX_BOOKMARK_POSITION => Ok(Some(v as f32)),+ Some(_) => Err(ToolError::InvalidArgs(format!("{key} must be between -{MAX_BOOKMARK_POSITION} and {MAX_BOOKMARK_POSITION} points"))),+ }+ }fn strs(&self, key: &str) -> Result<Vec<&str>> {let v = self.get(key).ok_or_else(|| Self::missing(key))?;let arr = v.as_array().ok_or_else(|| Self::wrong(key, "an array of strings"))?;diff --git a/crates/automation/src/tools.rs b/crates/automation/src/tools.rsindex e154e1eeb..11a19881a 100644--- a/crates/automation/src/tools.rs+++ b/crates/automation/src/tools.rs@@ -289,8 +289,21 @@ pub fn tools() -> Vec<ToolDef> {}),&["doc"],)),- t("bookmark_add", "Add a bookmark", "Add a bookmark that goes to a page, under a parent bookmark (or at the top level), at a position. Undoable.").with(schema(- json!({ "doc": doc(), "title": { "type": "string", "minLength": 1 }, "page": { "type": "integer", "minimum": 1 }, "parent": path("Parent bookmark (omit for the top level)"), "position": { "type": "integer", "minimum": 1, "description": "1-based position among the parent's children (default: last)." } }),+ t(+ "bookmark_add",+ "Add a bookmark",+ "Add a bookmark that goes to a page, under a parent bookmark (or at the top level), at a position. It goes to the top of the page, or to a place on it: `top` and `left` are points from the top-left of the displayed page (like the destination bookmark_list reports), each optional, and a coordinate left out keeps the reader's position that way. The zoom is kept. Undoable.",+ )+ .with(schema(+ json!({+ "doc": doc(),+ "title": { "type": "string", "minLength": 1 },+ "page": { "type": "integer", "minimum": 1 },+ "parent": path("Parent bookmark (omit for the top level)"),+ "position": { "type": "integer", "minimum": 1, "description": "1-based position among the parent's children (default: last)." },+ "top": { "type": "number", "minimum": -1000000, "maximum": 1000000, "description": "Points from the top of the displayed page." },+ "left": { "type": "number", "minimum": -1000000, "maximum": 1000000, "description": "Points from the left of the displayed page." }+ }),&["doc", "title", "page"],)),t("bookmark_rename", "Rename a bookmark", "Change a bookmark's title. Undoable.")diff --git a/crates/automation/tests/automation.rs b/crates/automation/tests/automation.rsindex cbf40f196..f89171382 100644--- a/crates/automation/tests/automation.rs+++ b/crates/automation/tests/automation.rs@@ -6855,3 +6855,64 @@ fn text_box_and_callout_fill_and_border_through_tools() {assert_eq!(session.get(saved).unwrap().comment_props(0, index).unwrap().fill, None);}}++/// Where the first bookmark on `path` goes, as `bookmark_list` reports it: points from the+/// top-left of the displayed page.+fn bookmark_destination(a: &mut Automation, doc: u64, title: &str) -> Value {+ let list = ok(a, "bookmark_list", json!({ "doc": doc }))["bookmarks"].clone();+ let row = list.as_array().unwrap().iter().find(|r| r["title"] == title).unwrap_or_else(|| panic!("{title} in {list}"));+ row["destination"].clone()+}++#[test]+fn a_bookmark_added_at_a_position_reports_the_same_position_back_on_any_page_rotation() {+ let dir = workdir("bookmark-position");+ let mut a = auto(&dir);+ let doc = ok(&mut a, "doc_open", json!({ "path": "a.pdf" }))["doc"].as_u64().unwrap();+ ok(&mut a, "page_rotate", json!({ "doc": doc, "pages": [3], "degrees": 90 }));+ let near = |v: &Value, want: Option<f64>, what: &str| match want {+ Some(w) => assert!((v.as_f64().unwrap_or_else(|| panic!("{what}: {v}")) - w).abs() < 0.05, "{what}: {v} vs {w}"),+ None => assert!(v.is_null(), "{what}: {v}"),+ };+ // Page 1 upright, page 3 turned a quarter: a displayed top and left come back as given.+ for (page, title) in [(1, "Upright"), (3, "Turned")] {+ for (suffix, left, top) in [(" both", Some(72.5), Some(120.25)), (" top", None, Some(200.0)), (" left", Some(50.0), None)] {+ let name = format!("{title}{suffix}");+ let mut args = json!({ "doc": doc, "title": name, "page": page });+ if let Some(l) = left {+ args["left"] = json!(l);+ }+ if let Some(t) = top {+ args["top"] = json!(t);+ }+ ok(&mut a, "bookmark_add", args);+ let d = bookmark_destination(&mut a, doc, &name);+ assert_eq!(d["fit"], "XYZ", "{name}");+ near(&d["left"], left, &format!("{name} left"));+ near(&d["top"], top, &format!("{name} top"));+ assert!(d["zoom"].is_null(), "the zoom is kept: {name}");+ }+ }+ // No position is the page top at the reader's zoom, as before.+ ok(&mut a, "bookmark_add", json!({ "doc": doc, "title": "Plain", "page": 2 }));+ let plain = bookmark_destination(&mut a, doc, "Plain");+ assert!(plain["left"].is_null() && plain["top"].is_null() && plain["zoom"].is_null(), "{plain}");++ // A position that is not a usable number is refused and adds nothing.+ let before = ok(&mut a, "bookmark_list", json!({ "doc": doc }))["bookmarks"].clone();+ for bad in [json!("high"), json!(2_000_000), json!(-2_000_000.5), json!(true)] {+ for key in ["top", "left"] {+ let args = json!({ "doc": doc, "title": "Bad", "page": 1, key: bad });+ assert!(matches!(a.call("bookmark_add", &args), Err(ToolError::InvalidArgs(_))), "{key} {bad}");+ }+ }+ assert_eq!(ok(&mut a, "bookmark_list", json!({ "doc": doc }))["bookmarks"], before, "nothing was added");++ // It survives a save and reopen.+ ok(&mut a, "doc_save", json!({ "doc": doc, "path": "placed.pdf" }));+ let mut b = auto(&dir);+ let re = ok(&mut b, "doc_open", json!({ "path": "placed.pdf" }))["doc"].as_u64().unwrap();+ let d = bookmark_destination(&mut b, re, "Turned both");+ near(&d["left"], Some(72.5), "reopened left");+ near(&d["top"], Some(120.25), "reopened top");+}diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex dfe11b25c..38d71998c 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -1321,11 +1321,16 @@ pub enum Edit {field_conflicts: pdfcraft_organize::FieldConflicts,},/// Add a bookmark to `page` as child `index` of the bookmark at `parent` (`[]` = top level).+ /// It goes to the user-space point (`left`, `top`) of the page at the reader's zoom, and+ /// either may be `None` to keep the reader's position that way (both `None` is the page top).+ /// A coordinate that is not finite fails the edit.AddBookmark {parent: Vec<usize>,index: usize,title: String,page: usize,+ left: Option<f64>,+ top: Option<f64>,},RenameBookmark {path: Vec<usize>,@@ -2355,8 +2360,8 @@ fn run_edit(doc: &mut pdfcraft_cos::Document, edit: &Edit, cx: &mut EditCtx) ->let outcome = pdfcraft_organize::insert_file_pages(doc, &src, &title, &pages, *at, *field_conflicts)?;cx.renamed_fields = outcome.renamed_fields;}- Edit::AddBookmark { parent, index, title, page } => {- pdfcraft_organize::add_bookmark(doc, parent, *index, title, *page)?;+ Edit::AddBookmark { parent, index, title, page, left, top } => {+ pdfcraft_organize::add_bookmark_at(doc, parent, *index, title, *page, *left, *top)?;}Edit::RenameBookmark { path, title } => pdfcraft_organize::rename_bookmark(doc, path, title)?,Edit::DeleteBookmark { path } => pdfcraft_organize::delete_bookmark(doc, path)?,diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rsindex f125c41da..3a219fa31 100644--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@ -1371,9 +1371,9 @@ fn outline_titles(items: &[pdfcraft_render::OutlineItem]) -> Vec<String> {fn bookmark_edits_show_in_the_viewer_undo_and_save() {let (mut s, id) = session_with(3);let titles = |s: &Session| outline_titles(&s.get(id).unwrap().info.outline);- s.apply(id, Edit::AddBookmark { parent: vec![], index: 0, title: "Start".into(), page: 0 }).unwrap();- s.apply(id, Edit::AddBookmark { parent: vec![], index: 1, title: "End".into(), page: 2 }).unwrap();- s.apply(id, Edit::AddBookmark { parent: vec![1], index: 0, title: "Détail".into(), page: 1 }).unwrap();+ s.apply(id, Edit::AddBookmark { parent: vec![], index: 0, title: "Start".into(), page: 0, left: None, top: None }).unwrap();+ s.apply(id, Edit::AddBookmark { parent: vec![], index: 1, title: "End".into(), page: 2, left: None, top: None }).unwrap();+ s.apply(id, Edit::AddBookmark { parent: vec![1], index: 0, title: "Détail".into(), page: 1, left: None, top: None }).unwrap();// The inspector (an independent parser) sees the same tree and destinations.assert_eq!(titles(&s), ["Start→1", "End→3[Détail→2]"]);s.apply(id, Edit::MoveBookmark { from: vec![1, 0], to_parent: vec![], index: 0 }).unwrap();@@ -2735,8 +2735,8 @@ fn split_by_size_and_bookmarks_and_page_filters() {assert_eq!(parts.last().unwrap().1, 6, "every page is in a part");assert_eq!(s.split_by_size(id, 1).unwrap().len(), 6, "pages larger than the limit stand alone");// Top-level bookmarks name the parts.- s.apply(id, Edit::AddBookmark { parent: vec![], index: 0, title: "Intro".into(), page: 0 }).unwrap();- s.apply(id, Edit::AddBookmark { parent: vec![], index: 1, title: "Results".into(), page: 3 }).unwrap();+ s.apply(id, Edit::AddBookmark { parent: vec![], index: 0, title: "Intro".into(), page: 0, left: None, top: None }).unwrap();+ s.apply(id, Edit::AddBookmark { parent: vec![], index: 1, title: "Results".into(), page: 3, left: None, top: None }).unwrap();assert_eq!(s.bookmark_splits(id), [(0, "Intro".to_string()), (3, "Results".to_string())]);// Filters: page numbers 2, 4, 6 are even.let info = &s.get(id).unwrap().info;@@ -6106,3 +6106,37 @@ fn undo_never_makes_an_unsaved_document_clean() {s.undo(new).unwrap();assert!(!s.get(new).unwrap().dirty, "once saved, undo back to the saved state is clean");}++#[test]+fn a_bookmark_added_at_a_point_goes_there_through_undo_and_save() {+ use pdfcraft_render::DestView;+ let (mut s, id) = session_with(3);+ let view = |s: &Session, i: usize| s.get(id).unwrap().info.outline.get(i).map(|o| (o.page, o.view));+ let add = |s: &mut Session, title: &str, page: usize, left: Option<f64>, top: Option<f64>| {+ s.apply(id, Edit::AddBookmark { parent: vec![], index: usize::MAX, title: title.into(), page, left, top })+ };+ add(&mut s, "Plain", 0, None, None).unwrap();+ add(&mut s, "Section", 1, None, Some(500.5)).unwrap();+ add(&mut s, "Table", 2, Some(72.0), Some(300.0)).unwrap();+ // The page top (no position) is what it always was; the others carry their place.+ assert_eq!(view(&s, 0), Some((Some(0), DestView::Xyz { left: None, top: None, zoom: None })));+ assert_eq!(view(&s, 1), Some((Some(1), DestView::Xyz { left: None, top: Some(500.5), zoom: None })));+ assert_eq!(view(&s, 2), Some((Some(2), DestView::Xyz { left: Some(72.0), top: Some(300.0), zoom: None })));++ // A position that is not a number fails the edit, which then changes nothing.+ for (left, top) in [(Some(f64::NAN), None), (None, Some(f64::INFINITY))] {+ assert!(matches!(add(&mut s, "Bad", 0, left, top), Err(EditError::Bookmark(_))), "{left:?} {top:?}");+ }+ assert_eq!(s.get(id).unwrap().info.outline.len(), 3);+ assert_eq!(s.get(id).unwrap().can_undo(), Some("Add bookmark"));++ s.undo(id).unwrap();+ assert_eq!(s.get(id).unwrap().info.outline.len(), 2);+ s.redo(id).unwrap();+ let saved = s.save_bytes(id).unwrap();+ let mut again = Session::new();+ let id2 = again.open("again.pdf", None, saved, None).unwrap();+ let outline = &again.get(id2).unwrap().info.outline;+ assert_eq!(outline[2].view, DestView::Xyz { left: Some(72.0), top: Some(300.0), zoom: None });+ assert_eq!(outline[1].view, DestView::Xyz { left: None, top: Some(500.5), zoom: None });+}diff --git a/crates/organize/src/lib.rs b/crates/organize/src/lib.rsindex 99c228c60..d4e032b46 100644--- a/crates/organize/src/lib.rs+++ b/crates/organize/src/lib.rs@@ -33,8 +33,8 @@ pub use import::{};pub use labels::{LabelRange, LabelStyle, PageLabels, number_pages, page_label_ranges, page_labels, set_page_label_ranges};pub use outline::{- Bookmark, BookmarkPage, OutlineEntry, OutlineError, add_bookmark, add_bookmark_tree, bookmark_page, bookmarks, delete_bookmark, move_bookmark,- rename_bookmark, set_bookmark_open, set_bookmark_page, top_level_bookmarks,+ Bookmark, BookmarkPage, OutlineEntry, OutlineError, add_bookmark, add_bookmark_at, add_bookmark_tree, bookmark_page, bookmarks, delete_bookmark,+ move_bookmark, rename_bookmark, set_bookmark_open, set_bookmark_page, top_level_bookmarks,};pub use transition::{TRANSITION_DIRECTIONS, TRANSITION_STYLES, Transition, TransitionSpec, set_transition};pub use view::{InitialView, displays_doc_title, initial_view, set_initial_view};diff --git a/crates/organize/src/outline.rs b/crates/organize/src/outline.rsindex dca0b35ce..39e601d73 100644--- a/crates/organize/src/outline.rs+++ b/crates/organize/src/outline.rs@@ -59,6 +59,8 @@ pub enum OutlineError {IntoItself,#[error("the title must not be empty")]EmptyTitle,+ #[error("a bookmark's position must be a finite number")]+ BadPosition,#[error("this document has no tagged headings to make bookmarks from")]NoEntries,#[error("{0}")]@@ -472,24 +474,55 @@ fn recount(doc: &mut Document) -> Result<()> {}fn destination(doc: &Document, page: usize) -> Result<Object> {+ destination_at(doc, page, None, None)+}++/// A destination on `page` (0-based) at the user-space point (`left`, `top`), either of which+/// may be left out to keep the reader's position in that direction.+fn destination_at(doc: &Document, page: usize, left: Option<f64>, top: Option<f64>) -> Result<Object> {+ if ![left, top].iter().flatten().all(|v| v.is_finite()) {+ return Err(OutlineError::BadPosition);+ }let pages = walk(doc)?;let (p, _) = pages.get(page).ok_or(OrganizeError::NoSuchPage(page))?;- Ok(go_to(*p))+ Ok(go_to_at(*p, left, top))}/// `/XYZ null null null`: go to the page, keeping the reader's zoom (what Acrobat writes for a/// new bookmark when the view has no specific position).fn go_to(page: ObjRef) -> Object {- Object::Array(vec![Object::Ref(page), Object::name("XYZ"), Object::Null, Object::Null, Object::Null])+ go_to_at(page, None, None)+}++/// `/XYZ left top null`: the point (`left`, `top`) at the window's upper-left corner, at the+/// reader's zoom; a coordinate that is left out keeps the reader's position.+fn go_to_at(page: ObjRef, left: Option<f64>, top: Option<f64>) -> Object {+ let coordinate = |v: Option<f64>| v.map_or(Object::Null, Object::Real);+ Object::Array(vec![Object::Ref(page), Object::name("XYZ"), coordinate(left), coordinate(top), Object::Null])}/// Add a bookmark titled `title` that goes to `page` (0-based), as child `index` of/// `parent_path` (`[]` = top level; an index past the end appends). Returns its path.pub fn add_bookmark(doc: &mut Document, parent_path: &[usize], index: usize, title: &str, page: usize) -> Result<Vec<usize>> {+ add_bookmark_at(doc, parent_path, index, title, page, None, None)+}++/// [`add_bookmark`] going to the user-space point (`left`, `top`) of `page`, as `/XYZ left top null`+/// (zoom kept). Either coordinate may be left out to keep the reader's position in that+/// direction; one that is not finite is refused.+pub fn add_bookmark_at(+ doc: &mut Document,+ parent_path: &[usize],+ index: usize,+ title: &str,+ page: usize,+ left: Option<f64>,+ top: Option<f64>,+) -> Result<Vec<usize>> {if title.trim().is_empty() {return Err(OutlineError::EmptyTitle);}- let dest = destination(doc, page)?;+ let dest = destination_at(doc, page, left, top)?;let parent = container(doc, parent_path)?;let mut kids = children_of(doc, parent, &mut HashSet::from([parent]));let mut d = Dict::new();diff --git a/crates/organize/src/tests.rs b/crates/organize/src/tests.rsindex 9bd3eb396..aed8eae85 100644--- a/crates/organize/src/tests.rs+++ b/crates/organize/src/tests.rs@@ -2821,3 +2821,40 @@ fn rotate_repeated_indices_accumulate_from_the_current_page_value() {}}}++#[test]+fn a_bookmark_can_go_to_a_point_on_its_page_and_survives_save() {+ let mut d = doc_a();+ // No position: as before, `/XYZ null null null`, the page top at the reader's zoom.+ crate::add_bookmark(&mut d, &[], 9, "Top", 0).unwrap();+ // Only a height (a bookmark made at the top of the window), a full point, and only a left.+ assert_eq!(crate::add_bookmark_at(&mut d, &[], 9, "Section", 1, None, Some(612.25)).unwrap(), vec![1]);+ crate::add_bookmark_at(&mut d, &[], 9, "Table", 1, Some(72.5), Some(300.0)).unwrap();+ crate::add_bookmark_at(&mut d, &[1], 9, "Inside", 2, Some(10.0), None).unwrap();+ let view = |d: &Document, title: &str| crate::bookmarks(d).into_iter().find(|b| b.title == title).unwrap().view;+ let xyz = |left, top| Some((b"XYZ".to_vec(), vec![left, top, None]));+ let check = |d: &Document| {+ assert_eq!(view(d, "Top"), xyz(None, None));+ assert_eq!(view(d, "Section"), xyz(None, Some(612.25)));+ assert_eq!(view(d, "Table"), xyz(Some(72.5), Some(300.0)));+ assert_eq!(view(d, "Inside"), xyz(Some(10.0), None));+ let page_of = |title: &str| crate::bookmarks(d).into_iter().find(|b| b.title == title).unwrap().page;+ assert_eq!((page_of("Top"), page_of("Section"), page_of("Table"), page_of("Inside")), (Some(0), Some(1), Some(1), Some(2)));+ };+ check(&d);+ check(&full_roundtrip(&d));+}++#[test]+fn a_bookmark_position_that_is_not_a_number_is_refused_and_changes_nothing() {+ let mut d = doc_a();+ crate::add_bookmark(&mut d, &[], 9, "Keep", 0).unwrap();+ for (left, top) in [(Some(f64::NAN), None), (None, Some(f64::INFINITY)), (Some(1.0), Some(f64::NEG_INFINITY))] {+ assert_eq!(crate::add_bookmark_at(&mut d, &[], 9, "Bad", 0, left, top), Err(crate::OutlineError::BadPosition), "{left:?} {top:?}");+ }+ assert_eq!(titles(&crate::bookmarks(&d)), ["Keep"]);+ // The page is still checked, and so is the title.+ assert!(crate::add_bookmark_at(&mut d, &[], 9, "Nowhere", 7, Some(1.0), Some(1.0)).is_err());+ assert_eq!(crate::add_bookmark_at(&mut d, &[], 9, " ", 0, Some(1.0), Some(1.0)), Err(crate::OutlineError::EmptyTitle));+ assert_eq!(titles(&crate::bookmarks(&d)), ["Keep"]);+}diff --git a/crates/render/src/inspect.rs b/crates/render/src/inspect.rsindex 0979f3d38..9598fede2 100644--- a/crates/render/src/inspect.rs+++ b/crates/render/src/inspect.rs@@ -219,6 +219,18 @@ impl PageInfo {[a * self.width, b * self.height]}+ /// A point as displayed (points from the page's top-left, y down, before any view rotation)+ /// → the `/XYZ` position `[left, top]` in user space that puts it at the window's top-left.+ /// Only a coordinate that is given is pinned: a bookmark made at the top of the window+ /// leaves the horizontal position alone. On a page turned a quarter, the displayed `y` decides+ /// the user `left` and the displayed `x` the user `top` (the inverse of [`Self::dest_fraction`]).+ /// A value that is not finite counts as not given.+ pub fn xyz_for_view(&self, x: Option<f32>, y: Option<f32>) -> [Option<f32>; 2] {+ let (x, y) = (x.filter(|v| v.is_finite()), y.filter(|v| v.is_finite()));+ let [ux, uy] = self.view_to_user(x.unwrap_or(0.0), y.unwrap_or(0.0));+ if self.rotation.is_multiple_of(180) { [x.map(|_| ux), y.map(|_| uy)] } else { [y.map(|_| ux), x.map(|_| uy)] }+ }+/// A destination's user-space point (each coordinate possibly unspecified) → the same point/// as a fraction of the displayed page `[x, y]` (0..1 from its top-left corner, y down),/// after `/Rotate` and a further clockwise `view_rotation` (0, 90, 180 or 270). On a page@@ -2778,6 +2790,41 @@ trailer << /Root 1 0 R >>assert!(flat.dest_fraction(Some(5.0), Some(-5.0), 0).iter().all(|f| f.is_some_and(|f| (0.0..=1.0).contains(&f))));}+ #[test]+ fn a_displayed_point_becomes_the_xyz_position_that_goes_back_to_it() {+ // Every rotation, on a crop box away from the origin: pinning a displayed point and+ // reading the destination back lands on the same fraction of the displayed page.+ for rotation in [0u16, 90, 180, 270] {+ let (width, height) = if rotation.is_multiple_of(180) { (300.0, 400.0) } else { (400.0, 300.0) };+ let p = PageInfo { width, height, label: "1".into(), crop: [100.0, 50.0, 400.0, 450.0], rotation };+ let (x, y) = (0.25 * width, 0.75 * height);+ let near = |got: [Option<f32>; 2], want: [Option<f32>; 2]| {+ for (g, w) in got.iter().zip(want) {+ match (g, w) {+ (Some(g), Some(w)) => assert!((g - w).abs() < 1e-4, "{rotation}: {got:?} vs {want:?}"),+ (None, None) => {}+ _ => panic!("{rotation}: {got:?} vs {want:?}"),+ }+ }+ };+ let [l, t] = p.xyz_for_view(Some(x), Some(y));+ assert!(l.is_some() && t.is_some(), "{rotation}: a point pins both");+ near(p.dest_fraction(l, t, 0), [Some(0.25), Some(0.75)]);+ // Only a height: the horizontal position is left alone, whichever user axis that is.+ let [l, t] = p.xyz_for_view(None, Some(y));+ assert_eq!((l.is_some(), t.is_some()), if rotation.is_multiple_of(180) { (false, true) } else { (true, false) }, "{rotation}");+ near(p.dest_fraction(l, t, 0), [None, Some(0.75)]);+ let [l, t] = p.xyz_for_view(Some(x), None);+ near(p.dest_fraction(l, t, 0), [Some(0.25), None]);+ assert_eq!(p.xyz_for_view(None, None), [None, None]);+ assert_eq!(p.xyz_for_view(Some(f32::NAN), Some(f32::INFINITY)), [None, None], "not finite is not given");+ }+ // The top of an upright page is the crop box's top edge.+ let p = PageInfo { width: 300.0, height: 400.0, label: "1".into(), crop: [100.0, 50.0, 400.0, 450.0], rotation: 0 };+ assert_eq!(p.xyz_for_view(None, Some(0.0)), [None, Some(450.0)]);+ assert_eq!(p.xyz_for_view(None, Some(100.0)), [None, Some(350.0)]);+ }+#[test]fn structure_failure_preserves_renderer_pages() {for crash in [true, false] {diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex eb9244a28..d95b2a48a 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -1036,6 +1036,53 @@ impl DocView {(!quads.is_empty()).then_some((s.page, quads))}+ /// Where a bookmark made now should go: the page and the `/XYZ` position `[left, top]` in user+ /// space. With text selected it is the corner of the selection that shows at its top-left+ /// (its page, both coordinates); otherwise the top of the window (the page showing there, and+ /// only the position along the window's vertical, so the reader's other scroll position and+ /// zoom are kept). `None` before the first frame has laid pages out, when the bookmark just+ /// goes to the current page.+ pub(crate) fn bookmark_position(&self, info: &DocInfo) -> Option<(usize, [Option<f32>; 2])> {+ if let Some(sel) = self.selection+ && let Some(text) = self.texts.get(&sel.page)+ && let Some(p) = info.pages.get(sel.page)+ {+ // The selection's bounds in view space, which View ▸ Rotate View leaves unturned: the+ // corner at the screen's top-left is a different one for each quarter turn.+ let [x0, y0, x1, y1] = sel.rects(text).iter().fold([f32::INFINITY, f32::INFINITY, f32::NEG_INFINITY, f32::NEG_INFINITY], |b, r| {+ [b[0].min(r[0]), b[1].min(r[1]), b[2].max(r[2]), b[3].max(r[3])]+ });+ let (x, y) = match self.rotation {+ 90 => (x0, y1),+ 180 => (x1, y1),+ 270 => (x1, y0),+ _ => (x0, y0),+ };+ if x.is_finite() && y.is_finite() {+ return Some((sel.page, p.xyz_for_view(Some(x), Some(y))));+ }+ }+ // The page showing at the window's top edge: one that crosses it (the first, in a spread+ // of pages of different heights, whose shorter page can start below it), else the+ // nearest one below.+ let top = self.viewport_screen.top();+ let showing = || self.screen_xforms.iter().filter(|(_, xf)| xf.rect.bottom() > top);+ let (page, xf) = showing()+ .filter(|(_, xf)| xf.rect.top() <= top)+ .min_by_key(|(p, _)| *p)+ .or_else(|| showing().min_by(|a, b| a.1.rect.top().total_cmp(&b.1.rect.top()).then(a.0.cmp(&b.0))))?;+ let p = info.pages.get(*page)?;+ // Above the page (in the gap before it) is the page's own top. The window's vertical is+ // the view's y, or its x when the view is turned a quarter.+ let (x, y) = xf.screen_to_view(pos2(xf.rect.center().x, top.max(xf.rect.top())));+ let at = if xf.rot.is_multiple_of(180) {+ p.xyz_for_view(None, Some(y.clamp(0.0, p.height)))+ } else {+ p.xyz_for_view(Some(x.clamp(0.0, p.width)), None)+ };+ Some((*page, at))+ }+/// A page's thumbnail texture, when rendered.pub(crate) fn thumb_id(&self, page: usize) -> Option<egui::TextureId> {self.thumbs.get(&page).map(|t| t.tex.id())diff --git a/crates/ui-egui/src/editing.rs b/crates/ui-egui/src/editing.rsindex 91480ac7b..839ff8775 100644--- a/crates/ui-egui/src/editing.rs+++ b/crates/ui-egui/src/editing.rs@@ -1070,7 +1070,11 @@ impl PdfCraftApp {let edit = match action {A::New => {let n = self.session.get(id).map_or(0, |d| d.info.outline.len());- self.apply_edit(Edit::AddBookmark { parent: vec![], index: n, title: "Untitled".into(), page: current });+ // Where the reader is: the selection's corner, else the top of the window.+ let (page, [left, top]) =+ self.session.get(id).and_then(|d| self.views.get(i)?.bookmark_position(&d.info)).unwrap_or((current, [None, None]));+ let (left, top) = (left.map(f64::from), top.map(f64::from));+ self.apply_edit(Edit::AddBookmark { parent: vec![], index: n, title: "Untitled".into(), page, left, top });// Like Acrobat: the new bookmark starts in rename mode.self.bookmark_rename = Some((vec![n], "Untitled".into()));self.right = Some(crate::RightPanel::Bookmarks);diff --git a/crates/ui-egui/tests/bookmark_position.rs b/crates/ui-egui/tests/bookmark_position.rsnew file mode 100644index 000000000..03fd8b50a--- /dev/null+++ b/crates/ui-egui/tests/bookmark_position.rs@@ -0,0 +1,228 @@+//! A new bookmark goes to where the reader is (#3865): the top of the window, or the corner of+//! the selected text, instead of the top of the page. Driven like a user would, with ⌘B.++use egui::{Key, Modifiers};+use egui_kittest::Harness;+use egui_kittest::kittest::Queryable;+use pdfcraft_engine::Edit;+use pdfcraft_render::DestView;+use pdfcraft_ui_egui::PdfCraftApp;++/// Three 300×400 pages, each with a line of Helvetica text at (40, 150), the first optionally+/// turned by `rotate` (the others upright).+fn fixture(rotate: u16) -> Vec<u8> {+ fixture_of(&[(300, 400); 3], rotate)+}++/// Pages of the given sizes (points), each with a line of Helvetica text at (40, 150), the first+/// turned by `rotate`.+fn fixture_of(sizes: &[(u32, u32)], rotate: u16) -> Vec<u8> {+ let n = sizes.len();+ let kids: Vec<String> = (0..n).map(|i| format!("{} 0 R", 3 + i)).collect();+ let (content, font) = (3 + n, 4 + n);+ let mut objs = vec!["<< /Type /Catalog /Pages 2 0 R >>".to_string(), format!("<< /Type /Pages /Kids [{}] /Count {n} >>", kids.join(" "))];+ for (i, (w, h)) in sizes.iter().enumerate() {+ let r = if i == 0 { format!(" /Rotate {rotate}") } else { String::new() };+ objs.push(format!(+ "<< /Type /Page /Parent 2 0 R{r} /MediaBox [0 0 {w} {h}] /Contents {content} 0 R /Resources << /Font << /F1 {font} 0 R >> >> >>"+ ));+ }+ let body = "BT /F1 14 Tf 40 150 Td (The quick brown fox) Tj ET";+ objs.push(format!("<< /Length {} >>\nstream\n{body}\nendstream", body.len()));+ objs.push("<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>".to_string());+ let mut out = b"%PDF-1.7\n".to_vec();+ let mut offsets = Vec::new();+ for (i, o) in objs.iter().enumerate() {+ offsets.push(out.len());+ out.extend_from_slice(format!("{} 0 obj\n{o}\nendobj\n", i + 1).as_bytes());+ }+ let xref = out.len();+ out.extend_from_slice(format!("xref\n0 {}\n0000000000 65535 f \n", objs.len() + 1).as_bytes());+ for o in offsets {+ out.extend_from_slice(format!("{o:010} 00000 n \n").as_bytes());+ }+ out.extend_from_slice(format!("trailer\n<< /Size {} /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n", objs.len() + 1).as_bytes());+ out+}++fn harness(rotate: u16) -> Harness<'static, PdfCraftApp> {+ let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| {+ let mut app = PdfCraftApp::new();+ app.set_option("language", "en").unwrap();+ app.open_bytes("text.pdf", None, fixture(rotate)).expect("opens");+ app.set_option("left", "closed").unwrap();+ app.set_option("panel", "bookmarks").unwrap();+ app+ });+ h.run_steps(4);+ settle(&mut h);+ h+}++/// Run frames until rendering has finished and the layout holds still.+fn settle(h: &mut Harness<'static, PdfCraftApp>) {+ for _ in 0..200 {+ h.run_steps(2);+ if !h.state().render_pending() {+ break;+ }+ std::thread::sleep(std::time::Duration::from_millis(5));+ }+}++/// Make a bookmark with ⌘B, as the Bookmarks button does, and say what it goes to.+fn new_bookmark(h: &mut Harness<'static, PdfCraftApp>) -> (Option<usize>, DestView) {+ h.key_press_modifiers(Modifiers::COMMAND, Key::B);+ h.run_steps(3);+ let id = h.state().views[0].id;+ let outline = &h.state().session.get(id).unwrap().info.outline;+ let made = outline.iter().find(|b| b.title == "Untitled").expect("the new bookmark");+ (made.page, made.view)+}++fn xyz(view: DestView) -> (Option<f32>, Option<f32>) {+ match view {+ DestView::Xyz { left, top, zoom } => {+ assert_eq!(zoom, None, "the reader's zoom is kept");+ (left, top)+ }+ other => panic!("expected /XYZ, got {other:?}"),+ }+}++fn close(got: Option<f32>, want: f32, what: &str) {+ let got = got.unwrap_or_else(|| panic!("{what} is set"));+ assert!((got - want).abs() < 1.0, "{what}: {got} vs {want}");+}++#[test]+fn a_new_bookmark_goes_to_the_top_of_the_window_not_the_top_of_the_page() {+ let mut h = harness(0);+ // A bookmark that scrolls page 2 to 250 pt up its height puts that line at the top of the+ // window; a bookmark made there then goes to the same place.+ h.state_mut().apply_edit(Edit::AddBookmark { parent: vec![], index: 0, title: "Mid".into(), page: 1, left: None, top: Some(250.0) });+ h.run_steps(3);+ h.get_by_label("Mid").click();+ settle(&mut h);+ let (page, view) = new_bookmark(&mut h);+ assert_eq!(page, Some(1), "the page at the top of the window");+ let (left, top) = xyz(view);+ close(top, 250.0, "top");+ assert_eq!(left, None, "the horizontal position is the reader's");+}++#[test]+fn a_bookmark_made_at_the_start_goes_to_the_top_of_the_first_page() {+ let mut h = harness(0);+ let (page, view) = new_bookmark(&mut h);+ assert_eq!(page, Some(0));+ let (left, top) = xyz(view);+ close(top, 400.0, "top is the page's top edge");+ assert_eq!(left, None);+}++#[test]+fn a_bookmark_made_with_text_selected_goes_to_the_selections_corner() {+ let mut h = harness(0);+ // "quick brown": the selection starts after "The ", 40 pt in plus its width, on the line at 150.+ h.state_mut().views[0].select_text(0, 4, 15);+ h.run_steps(3);+ let (page, view) = new_bookmark(&mut h);+ assert_eq!(page, Some(0), "the selection's page");+ let (left, top) = xyz(view);+ let left = left.expect("left is set from the selection");+ let top = top.expect("top is set from the selection");+ assert!((66.0..=70.0).contains(&left), "left is where 'q' starts: {left}");+ assert!((155.0..=168.0).contains(&top), "top is above the baseline at 150: {top}");+}++#[test]+fn a_bookmark_made_on_a_turned_page_pins_the_axis_the_window_scrolls_along() {+ // Page 1 is turned a quarter: its displayed top is a user x, so that is what is pinned.+ let mut h = harness(90);+ let (page, view) = new_bookmark(&mut h);+ assert_eq!(page, Some(0));+ let (left, top) = xyz(view);+ close(left, 0.0, "left is the displayed top edge");+ assert_eq!(top, None, "the displayed horizontal position is the reader's");+}++/// Turn the view a quarter at a time (View ▸ Rotate View) and let the layout settle.+fn rotate_view(h: &mut Harness<'static, PdfCraftApp>, degrees: u16) {+ h.state_mut().views[0].rotation = degrees;+ h.run_steps(3);+ settle(h);+}++#[test]+fn a_bookmark_made_in_a_turned_view_pins_the_axis_that_is_vertical_on_screen() {+ // At the start of the document the window's top edge is the first page's top as displayed.+ // Turned clockwise a quarter, that edge is the page's left; half a turn, its bottom; three+ // quarters, its right. The other coordinate is the reader's, so it stays unset.+ for (degrees, left, top) in [(90, Some(0.0), None), (180, None, Some(0.0)), (270, Some(300.0), None)] {+ let mut h = harness(0);+ rotate_view(&mut h, degrees);+ let (page, view) = new_bookmark(&mut h);+ assert_eq!(page, Some(0), "{degrees}");+ let (l, t) = xyz(view);+ match (left, top) {+ (Some(want), None) => {+ close(l, want, &format!("{degrees}: left"));+ assert_eq!(t, None, "{degrees}: top is the reader's");+ }+ (None, Some(want)) => {+ close(t, want, &format!("{degrees}: top"));+ assert_eq!(l, None, "{degrees}: left is the reader's");+ }+ _ => unreachable!("one axis is pinned"),+ }+ }+}++#[test]+fn a_bookmark_made_with_text_selected_in_a_turned_view_goes_to_the_corner_shown_top_left() {+ // The selection "quick brown" spans x from about 68 to 143 and y from just under the baseline+ // at 150 to just above its ascent. Its bounds' corner at the screen's top-left is the+ // upper-left (0), lower-left (90), lower-right (180) or upper-right (270) one in the page.+ for (degrees, right_end, upper) in [(0, false, true), (90, false, false), (180, true, false), (270, true, true)] {+ let mut h = harness(0);+ rotate_view(&mut h, degrees);+ h.state_mut().views[0].select_text(0, 4, 15);+ h.run_steps(3);+ let (page, view) = new_bookmark(&mut h);+ assert_eq!(page, Some(0), "{degrees}");+ let (left, top) = xyz(view);+ let (left, top) = (left.expect("left"), top.expect("top"));+ assert_eq!(left > 105.0, right_end, "{degrees}: left {left} is the {} end", if right_end { "right" } else { "left" });+ if upper {+ assert!((155.0..=168.0).contains(&top), "{degrees}: top {top} is above the baseline at 150");+ } else {+ assert!((140.0..=152.0).contains(&top), "{degrees}: top {top} is at the bottom of the text");+ }+ }+}++#[test]+fn a_bookmark_in_a_spread_of_unequal_pages_goes_to_the_page_crossing_the_top_of_the_window() {+ use pdfcraft_ui_egui::canvas::PageLayout;+ // Pages 1 and 2 share a row; page 1 is shorter, so it is centred and starts below page 2's top.+ let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| {+ let mut app = PdfCraftApp::new();+ app.set_option("language", "en").unwrap();+ app.open_bytes("spread.pdf", None, fixture_of(&[(300, 200), (300, 400), (300, 400)], 0)).expect("opens");+ app.set_option("left", "closed").unwrap();+ app.set_option("panel", "bookmarks").unwrap();+ app+ });+ h.state_mut().views[0].layout = PageLayout::TwoUp;+ h.run_steps(4);+ settle(&mut h);+ // 20 pt below page 2's top is at the window's top, where page 1 has not started.+ h.state_mut().apply_edit(Edit::AddBookmark { parent: vec![], index: 0, title: "Right".into(), page: 1, left: None, top: Some(380.0) });+ h.run_steps(3);+ h.get_by_label("Right").click();+ settle(&mut h);+ let (page, view) = new_bookmark(&mut h);+ assert_eq!(page, Some(1), "page 2 crosses the top of the window; page 1 starts below it");+ close(xyz(view).1, 380.0, "top");+}diff --git a/crates/ui-egui/tests/bookmarks.rs b/crates/ui-egui/tests/bookmarks.rsindex 6d94fb633..f180799a5 100644--- a/crates/ui-egui/tests/bookmarks.rs+++ b/crates/ui-egui/tests/bookmarks.rs@@ -156,7 +156,7 @@ fn search_finds_collapsed_bookmarks_and_keeps_original_paths() {for (parent, index, title, page) in[(vec![], 0, "Unrelated", 0), (vec![], 1, "Reports", 0), (vec![1], 0, "Other chapter", 1), (vec![1], 1, "Résumé results", 2)]{- h.state_mut().apply_edit(Edit::AddBookmark { parent, index, title: title.into(), page });+ h.state_mut().apply_edit(Edit::AddBookmark { parent, index, title: title.into(), page, left: None, top: None });}h.run_steps(3);h.get_by_label("Bookmark options").click();@@ -252,7 +252,7 @@ fn expanding_and_collapsing_all_bookmarks() {use pdfcraft_engine::Edit;let mut h = harness();for (parent, title) in [(vec![], "Part"), (vec![0], "Chapter"), (vec![0, 0], "Section")] {- h.state_mut().apply_edit(Edit::AddBookmark { parent, index: 0, title: title.into(), page: 0 });+ h.state_mut().apply_edit(Edit::AddBookmark { parent, index: 0, title: title.into(), page: 0, left: None, top: None });}h.run_steps(3);let shown = |h: &Harness<'static, PdfCraftApp>, t: &str| h.query_by_label(t).is_some();diff --git a/crates/ui-egui/tests/control.rs b/crates/ui-egui/tests/control.rsindex e6af166d7..13ffcfd14 100644--- a/crates/ui-egui/tests/control.rs+++ b/crates/ui-egui/tests/control.rs@@ -154,7 +154,7 @@ fn control_button_focus_preserves_document_undo_redo_shortcuts() {#[test]fn control_text_focus_retains_text_undo_ownership() {let (mut h, c) = harness_pages(2);- h.state_mut().apply_edit(pdfcraft_engine::Edit::AddBookmark { parent: vec![], index: 0, title: "Target".into(), page: 0 });+ h.state_mut().apply_edit(pdfcraft_engine::Edit::AddBookmark { parent: vec![], index: 0, title: "Target".into(), page: 0, left: None, top: None });ok(&mut h, &c, "ui.command", json!({"id": "page.insert_blank"}));ok(&mut h, &c, "ui.set", json!({"key": "panel", "value": "bookmarks"}));let widgets = ok(&mut h, &c, "ui.inspect", json!({"query": "Search", "role": "TextInput"}));@@ -239,7 +239,7 @@ fn control_quit_clean_document_requests_normal_window_close() {fn bookmark_titles_can_be_searched_over_control() {let (mut h, c) = harness();for (index, title, page) in [(0, "Background", 0), (1, "Target chapter", 3)] {- h.state_mut().apply_edit(pdfcraft_engine::Edit::AddBookmark { parent: vec![], index, title: title.into(), page });+ h.state_mut().apply_edit(pdfcraft_engine::Edit::AddBookmark { parent: vec![], index, title: title.into(), page, left: None, top: None });}ok(&mut h, &c, "ui.set", json!({ "key": "panel", "value": "bookmarks" }));h.run_steps(3);@@ -1361,8 +1361,22 @@ fn docking_renders_real_pdf_default_floating_and_redocked() {let (mut h, c) = harness_pages_at(5, width, scale);ok(&mut h, &c, "ui.resize", json!({"width":width,"height":900}));ok(&mut h, &c, "ui.set", json!({"key":"panel","value":"bookmarks"}));- h.state_mut().apply_edit(pdfcraft_engine::Edit::AddBookmark { parent: vec![], index: 0, title: "Overview".into(), page: 0 });- h.state_mut().apply_edit(pdfcraft_engine::Edit::AddBookmark { parent: vec![], index: 1, title: "Details".into(), page: 2 });+ h.state_mut().apply_edit(pdfcraft_engine::Edit::AddBookmark {+ parent: vec![],+ index: 0,+ title: "Overview".into(),+ page: 0,+ left: None,+ top: None,+ });+ h.state_mut().apply_edit(pdfcraft_engine::Edit::AddBookmark {+ parent: vec![],+ index: 1,+ title: "Details".into(),+ page: 2,+ left: None,+ top: None,+ });for state in ["default", "floating", "redocked"] {if state == "floating" {ok(&mut h, &c, "ui.dock", json!({"operation":"float", "panel":"inspector", "rect":[160,100,330,480]}));diff --git a/crates/ui-egui/tests/editing.rs b/crates/ui-egui/tests/editing.rsindex d41041e52..fa45322f1 100644--- a/crates/ui-egui/tests/editing.rs+++ b/crates/ui-egui/tests/editing.rs@@ -1983,7 +1983,14 @@ fn split_at_bookmarks_with_equal_titles_keeps_every_part() {let mut h = organize(3);h.state_mut().export_dir_override = Some(dir.to_string_lossy().into_owned());for (index, title) in [(0, "Same"), (1, "Same"), (2, "same")] {- h.state_mut().apply_edit(pdfcraft_engine::Edit::AddBookmark { parent: vec![], index, title: title.into(), page: index });+ h.state_mut().apply_edit(pdfcraft_engine::Edit::AddBookmark {+ parent: vec![],+ index,+ title: title.into(),+ page: index,+ left: None,+ top: None,+ });}h.state_mut().split_draft.mode = pdfcraft_ui_egui::SplitMode::Bookmarks;h.state_mut().run_command("page.split");diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.tomlindex 7aca7d5c8..6b881617e 100644--- a/parity/acrobat-features.toml+++ b/parity/acrobat-features.toml@@ -3244,8 +3244,8 @@ milestone = "M4"status = "shipped"commands = ["bookmark.add"]tools = ["bookmark_add"]-evidence = ["crates/ui-egui/tests/bookmarks.rs::new_rename_reorder_indent_delete_and_undo", "crates/organize/src/tests.rs::bookmarks_add_rename_move_delete", "crates/engine/src/tests.rs::bookmark_edits_show_in_the_viewer_undo_and_save", "crates/automation/tests/automation.rs::bookmarks_through_tools"]-notes = ""+evidence = ["crates/ui-egui/tests/bookmarks.rs::new_rename_reorder_indent_delete_and_undo", "crates/organize/src/tests.rs::bookmarks_add_rename_move_delete", "crates/engine/src/tests.rs::bookmark_edits_show_in_the_viewer_undo_and_save", "crates/automation/tests/automation.rs::bookmarks_through_tools", "crates/ui-egui/tests/bookmark_position.rs::a_new_bookmark_goes_to_the_top_of_the_window_not_the_top_of_the_page", "crates/ui-egui/tests/bookmark_position.rs::a_bookmark_made_with_text_selected_goes_to_the_selections_corner", "crates/ui-egui/tests/bookmark_position.rs::a_bookmark_made_on_a_turned_page_pins_the_axis_the_window_scrolls_along", "crates/ui-egui/tests/bookmark_position.rs::a_bookmark_made_in_a_turned_view_pins_the_axis_that_is_vertical_on_screen", "crates/ui-egui/tests/bookmark_position.rs::a_bookmark_made_with_text_selected_in_a_turned_view_goes_to_the_corner_shown_top_left", "crates/ui-egui/tests/bookmark_position.rs::a_bookmark_in_a_spread_of_unequal_pages_goes_to_the_page_crossing_the_top_of_the_window", "crates/organize/src/tests.rs::a_bookmark_can_go_to_a_point_on_its_page_and_survives_save", "crates/engine/src/tests.rs::a_bookmark_added_at_a_point_goes_there_through_undo_and_save", "crates/automation/tests/automation.rs::a_bookmark_added_at_a_position_reports_the_same_position_back_on_any_page_rotation"]+notes = "A new bookmark goes to where the reader is (#3865): the top-left of the selected text, or with nothing selected the top of the window on the page showing there, as /XYZ left top null (the reader's zoom is kept, and the horizontal position too when only the top is pinned). The window's vertical is what is pinned: on a page turned a quarter (or a view turned with View ▸ Rotate View) that is a user x, and the selection's corner is the one shown at the top-left. In a two-up spread the page crossing the window's top edge is the one used. bookmark_add takes top and left in points from the top-left of the displayed page, the same as bookmark_list reports. Missing: Set to current page (and Set Destination) still go to the page top, the zoom is not recorded, and a bookmark made while a page is only partly laid out (before the first frame) goes to the page top."[[feature]]id = "organize.bookmark-rename"