From b19498cb085730841a2eb07b3fa673e77c4dab8d Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 23 Nov 2026 07:44:01 -0500 Subject: [PATCH] prod merge: open parameters' named destination is looked up with the document, so the tab opens at it (production looked it up inline at launch) --- crates/ui-egui/src/app/files.rs | 25 ++++++++++++++++++---- crates/ui-egui/src/app/links.rs | 9 ++++++++ crates/ui-egui/src/platform/open_worker.rs | 14 ++++++++++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/app/files.rs b/crates/ui-egui/src/app/files.rs index af3b6668c0..7254d02c46 100644 --- a/crates/ui-egui/src/app/files.rs +++ b/crates/ui-egui/src/app/files.rs @@ -144,7 +144,18 @@ impl PdfCraftApp { // session keeps the document in front's. let context = self.session.open_context().with_highlight(self.highlight_fields); // PLAN: `highlight_fields` on the app (pdf-canvas-w8) let job = - open_worker::Job { context, name: request.name.clone(), path: request.path.clone(), password: request.password, input: request.input }; + open_worker::Job { + context, + name: request.name.clone(), + path: request.path.clone(), + password: request.password, + input: request.input, + // A named destination is looked up with the document, so the tab opens at it. + named: match &request.after_open { + Some(pdfcraft_render::RemoteDestination::Named(name)) => Some(name.clone()), + _ => None, + }, + }; self.opens.submit(token, request.priority, move |cancel| open_worker::run(job, cancel)); self.pending_opens.push(PendingOpen { token, @@ -251,7 +262,7 @@ impl PdfCraftApp { } Err(error) => self.notify_fmt("Couldn't open {name}: {e}", &[("name", &pending.name), ("e", &error)]), }, - open_worker::ResultKind::Prepared { bytes, result } => match *result { + open_worker::ResultKind::Prepared { bytes, result, named } => match *result { Ok(prepared) => match self.finish_open(ctx, &pending.name, pending.path.clone(), bytes.len(), prepared, pending.activate) { Ok(id) => { if let Some(path) = pending.path.as_deref() { @@ -260,8 +271,14 @@ impl PdfCraftApp { self.forget_closed_tab(path); } } - if let Some(destination) = pending.after_open { - self.apply_remote_destination(destination); + match (pending.after_open, named) { + // The open looked the name up with the document; a later request for another place + // replaced it, and that one is shown as asked. + (Some(pdfcraft_render::RemoteDestination::Named(name)), Some((looked_up, found))) if looked_up == name => { + self.apply_looked_up_destination(name, found); + } + (Some(destination), _) => self.apply_remote_destination(destination), + (None, _) => {} } if let Some((layout, continuous)) = pending.display_override && let Some(view) = self.views.iter_mut().find(|view| view.id == id) diff --git a/crates/ui-egui/src/app/links.rs b/crates/ui-egui/src/app/links.rs index eb1f9d46fe..805f5d7dca 100644 --- a/crates/ui-egui/src/app/links.rs +++ b/crates/ui-egui/src/app/links.rs @@ -70,6 +70,15 @@ impl PdfCraftApp { } } + /// Show the named destination `name` that an open looked up with its document (`found`), in the tab it just + /// opened. + #[cfg(not(target_arch = "wasm32"))] + pub(super) fn apply_looked_up_destination(&mut self, name: String, found: Option<(usize, pdfcraft_render::DestView)>) { + if let Some(index) = self.views.len().checked_sub(1) { + self.show_destination_at(index, found_destination(found, name)); + } + } + /// Show `destination` in the tab at `index`: a document just opened from a link or with open /// parameters (#3425), or one already open that such a link or launch names. The latest request /// for a document wins over a named destination still being looked up. diff --git a/crates/ui-egui/src/platform/open_worker.rs b/crates/ui-egui/src/platform/open_worker.rs index 9d0ee77d7a..c7b162fe3f 100644 --- a/crates/ui-egui/src/platform/open_worker.rs +++ b/crates/ui-egui/src/platform/open_worker.rs @@ -24,6 +24,9 @@ pub(crate) enum ResultKind { Prepared { bytes: Arc>, result: Box>, + /// The named destination the open was asked to show and what the document's name tree says of it, looked + /// up here with the document so the tab opens at it (#3425). + named: Option<(String, Option<(usize, pdfcraft_render::DestView)>)>, }, ReadFailed(String), RemoteFailed(String), @@ -38,6 +41,8 @@ pub(crate) struct Job { pub path: Option, pub password: Option>, pub input: Input, + /// The named destination to look up once the document is prepared. + pub named: Option, } /// The queue that prepares opens: one lane, oldest first, so files open in the order they were @@ -86,8 +91,13 @@ fn prepare(job: Job, cancel: &Cancel) -> ResultKind { Some(SourceKind::Office) => return ResultKind::Converted(pdfcraft_engine::office_to_pdf(&job.name, &bytes).map_err(|e| e.to_string())), Some(SourceKind::Pdf) | None => {} } - let result = job.context.prepare_open(job.name, job.path, bytes.clone(), job.password.as_deref().map(String::as_str)); - ResultKind::Prepared { bytes, result: Box::new(result) } + let password = job.password.as_deref().map(String::as_str); + let result = job.context.prepare_open(job.name, job.path, bytes.clone(), password); + let named = job + .named + .filter(|_| result.is_ok() && !cancel.is_cancelled()) + .map(|name| (name.clone(), pdfcraft_render::named_destination(bytes.clone(), password, &name))); + ResultKind::Prepared { bytes, result: Box::new(result), named } } #[cfg(all(test, not(target_arch = "wasm32")))]