Skip to content

mac: File ▸ Print… (⌘P) prints the compiled PDF, Print Source… prints the buffer - #425

Merged
GoKubar merged 3 commits into
mainfrom
agent/daniel-parent/preview-print
Sep 14, 2026
Merged

GoKubar merged 3 commits into
mainfrom
agent/daniel-parent/preview-print

Conversation

@d-q222

@d-q222 d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

daniel-parent (Cursor Grok lane preview-print, reviewed by daniel-parent plus an independent read-only Codex review). The Mac app couldn't print; ⌘P was unbound.

What changes

  • File ▸ Print… (⌘P) prints the compiled document through PDFExport.render(result, dark: false), the same render path as Export PDF, so no second PDF implementation. A stale compile prints the stored result, as Export does.
  • File ▸ Print Source… prints the editor text in a monospaced font with line numbers. It builds its own NSTextStorage, NSLayoutManager and NSTextView, so the live editor view is never touched.
  • Enablement:
    • Print is disabled when there's no result, the compile failed, or there are no pages. Its help says why ("Compile failed — nothing to print").
    • Print Source is disabled when no document is open.
    • Both checks read the model's existing change-only toolbar mirrors, adding toolbarPageCount and toolbarHasDocument, so the App scene doesn't re-read result/documents on every keystroke.
    • PrintController repeats the same checks, so a palette or accessibility invocation can't bypass them.
  • Shared refusal: Export PDF's refusal checks (historical snapshot, no result, v1 pages elided) are now PDFExport.exportPDFRefusal(), shared with Print instead of copied.
  • Discoverability: the command palette, AccessibilityCommands and the README shortcut table all list both commands.

Review round

The independent review found three problems, all fixed at be8431d1:

  1. A failed result printed a blank page. PDFExport.render emits a blank letter page for pages: [].
  2. Print Source was always enabled, with hasDocument: true hard-coded in its help.
  3. PrintController didn't check that a document exists.

Tests

  • PrintControllerTests (9) cover:
    • the page count, paper size and job title of the NSPrintOperation, built without running it;
    • a stale compile;
    • the source text matching the buffer;
    • a failed result, empty pages and no document;
    • the actual menu-state functions.
  • Full swift test (apps/mac) at be8431d1: Executed 1145 tests, with 135 tests skipped and 0 failures.

Overlap check

Not done

  • Not driven in a live print dialog; the print operations are built and inspected in tests.
  • Export PDF… still opens its save panel for a failed result. That's Export's existing behaviour, left unchanged here.
  • If the v2-only pane elided the v1 pages (status ok, no pages), Print's help still says "Compile failed". The item is correctly disabled, but the wording is imprecise.

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

d-q222 and others added 3 commits September 14, 2026 10:09
…ations

Add PrintController.swift so File > Print can reuse PDFExport.render (the
Export PDF path) and File > Print Source can print a copy of the editor
buffer with line numbers. Tests build NSPrintOperation without running it
and check page count, paper size, job title, disabled/no-PDF state, stale
compile matching Export PDF, and source text equalling the buffer.

Ran: cd apps/mac && swift test --filter PrintControllerTests
Result: Executed 6 tests, with 0 failures (0 unexpected) in 0.066 (0.067) seconds

Next: File menu (replacing .printItem, ⌘P), palette, AccessibilityCommand,
README rows, then merge origin/main.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
Wire File > Print… (⌘P; was unbound — palette is ⌘⇧P, pin is ⌘⌥P) and
File > Print Source… through PrintController. Replacing .printItem lives in
a second .commands block so SwiftUI's 10-child CommandsBuilder still
compiles. AccessibilityCommand, palette, README shortcuts, and the
command-table parser follow.

Ran: cd apps/mac && swift test --filter 'PrintControllerTests|CommandTableTests|WorkspaceShellTests'
Result: Executed 24 tests, with 0 failures (0 unexpected) in 0.219 (0.221) seconds
  CommandTableTests: Executed 8 tests, with 0 failures
  PrintControllerTests: Executed 6 tests, with 0 failures
  WorkspaceShellTests: Executed 10 tests, with 0 failures

Next: git fetch origin main && git merge origin/main (no rebase), then full
swift test in apps/mac.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
…Source with no document

Print… was enabled for any non-nil result, so a .failed compile with no pages
went through PDFExport.render as a blank one-page PDF. File > Print now calls
PrintController.documentEnabled (change-only mirrors: toolbarHasResult,
resultStatus, toolbarPageCount) and printableResult refuses the same cases
with "Compile failed — nothing to print". Print Source uses toolbarHasDocument
instead of a hard-coded hasDocument: true. Export PDF… and Print share
ShellModel.exportPDFRefusal; retainedMarks stays diagnostics-only because
Export does not fall back to it.

Ran: cd apps/mac && swift test --filter 'PrintControllerTests|CommandTableTests'
Result: Executed 17 tests, with 0 failures (0 unexpected) in 0.260 (0.262) seconds
  CommandTableTests: Executed 8 tests, with 0 failures
  PrintControllerTests: Executed 9 tests, with 0 failures

Next: git fetch origin main && git merge origin/main (no rebase), then full
swift test in apps/mac.

Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants