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)

This commit is contained in:
Dylan M. Taylor committed 2026-11-23 07:44:01 -05:00
1 parent 8c68ea2dcc
commit b19498cb08
3 files changed
+42 -6

No files matched your search

+21 -4
View File
@@ -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)
+9
View File
@@ -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.
+12 -2
View File
@@ -24,6 +24,9 @@ pub(crate) enum ResultKind {
Prepared {
bytes: Arc<Vec<u8>>,
result: Box<Result<PreparedDocument, OpenError>>,
/// 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<String>,
pub password: Option<zeroize::Zeroizing<String>>,
pub input: Input,
/// The named destination to look up once the document is prepared.
pub named: Option<String>,
}
/// 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")))]