Record background print hooks as one command

This commit is contained in:
skylar taylor-barrick committed 2026-10-12 02:58:32 +02:00
1 parent cc902c681b
commit 4bb6ffc46f
2 files changed
+11 -1

No files matched your search

+8 -1
View File
@@ -751,18 +751,25 @@ impl Session {
};
self.coalesce_request = coalesce.clone();
self.color_restrict = *color_restrict;
// Apply-time hooks can dispatch commands too. Keep the same single-step recording
// contract as synchronous dispatch without truncating work done while the worker ran.
let nested_from = self.journal.len();
let recording = if *journal && crate::actions_cmds::replayable(command) { self.actions.recording.take() } else { None };
let r = match apply {
Some(f) => std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| f(self, payload)))
.unwrap_or_else(|_| Err(EngineError::Other(format!("`{label}` failed with an internal error (logged); the document is unchanged")))),
None => Err(EngineError::Other("internal error: job applied twice".into())),
};
if self.actions.recording.is_none() {
self.actions.recording = recording;
}
self.coalesce_request = None;
self.color_restrict = None;
// Finish successful command bookkeeping on the document the job edited.
// Restoring the viewed document first would attribute Fade and slice updates
// to that document instead, when the user switched tabs mid-job.
if r.is_ok() {
self.after_command(command, params.clone(), *journal, None);
self.after_command(command, params.clone(), *journal, Some(nested_from));
}
// Keep the user's active document unless the job opened a new one.
// This also restores the selection when the apply step returned an error.
+3
View File
@@ -254,7 +254,10 @@ fn spool_transport_streams_pdf_and_propagates_refusal() {
assert!(s.execute("jobs.cancel", json!({"job": job.0})).unwrap_err().to_string().contains("system print queue"));
s.execute("file.new", json!({"width": 40, "height": 10})).unwrap();
let viewed = s.active().unwrap().doc.id;
let journal_before_completion = s.journal.len();
let out = s.wait_job(job).unwrap();
assert_eq!(s.journal.len(), journal_before_completion + 1, "print hooks must not become duplicate recorded action steps");
assert_eq!(s.journal.last().unwrap().0, "file.print");
assert_eq!(s.active().unwrap().doc.id, viewed, "completion keeps the user's tab");
assert_eq!(s.active().unwrap().doc.size.width, 40, "print hook must not act on the newly viewed document");
let printed = &s.documents().iter().find(|st| st.doc.id == source).unwrap().doc;