feat(export): Export as PDF gets a keyboard shortcut (#673) - #679
Merged
Conversation
Mod+Shift+P, bound in both keyboard layers — the document handler and the editor's own action table — so it works in reading and edit mode. The menu item now prints the chord beside its label. Not the Mod+Shift+E the request suggested: Inline Code has held that since the formatting chords went in. P is the print mnemonic, and the unshifted Mod+P is already the command palette. The menu hides Export for a document with nothing in it; that condition becomes `hasExportableDocument` so the chord is gated by the same one rather than a second copy of it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
Closes #673, asked by @zhouchang3462: Export as PDF was menu-only, which is slow for anyone exporting repeatedly.
Mod+Shift+Pnow runs it, in reading mode and in edit mode, and the menu item prints the chord beside its label so it is discoverable from where people look today.Mechanism
Not the
Ctrl+Shift+Ethe request suggested — Inline Code has held that chord since the formatting shortcuts went in, and the editor toolbar prints it, so taking it would break a documented binding to add a new one.Pis the print mnemonic every desktop app shares, and Markpad's unshiftedMod+Pis the command palette (where Obsidian also puts it), so the shifted spelling is both free and the nearest thing to Print. No other entry claims it on any platform, whichshortcutRegistry.test.tschecks.The chord is bound in both keyboard layers, because they are genuinely separate: outside the editor,
viewerKeymap.tsmaps the keystroke to anexport-pdfcommand the viewer dispatches; inside it, Monaco resolves its own keybindings first and callsstopPropagation, so aneditor.addActionentry is what makes the chord work in edit mode. Registering only one leaves it dead in the other mode.The empty-document gate ended up mattering more than expected. The menu hides both Export items when there is nothing to export, and the first version of this repeated that condition at the chord's dispatch. Measured with the chord actually pressed, that guard held in reading mode and did nothing in edit mode — the editor's action calls the export function directly, one layer below the dispatcher. So the condition now lives at the top of
exportAsPdfitself, and is the exportedhasExportableDocumentthe menu gate also switched to, rather than a third spelling of it.Measured by pressing the chord and watching the Tauri commands the frontend issues:
# Export merender_markdown,print_pdf# Export meprint_pdfrender_markdownappears only in edit mode because the export refreshes a preview that may be stale — the pre-existingsyncPreviewForPrintstep, unchanged here.Scope
Export as HTML keeps its menu-only route. The request was about PDF, the registry makes a second entry a few lines, and picking a chord for it is a decision nobody has asked for yet.
No new setting: the chord is fixed, like every other one in the app. If rebindable shortcuts arrive, this entry travels with the rest.
Tests
No new test file.
shortcutRegistry.test.tsalready holds this shape and covers the entry as soon as it exists — changing the registry's chord to something unbound turns three of its assertions red (every chord the registry advertises is the chord the editor really registers,…runs the command it names, outside the editor,every chord the document handler answers is advertised). Checked by doing it.renderedHtmlField.spec.tsneeded one line: it parses the export menu's{#if}out ofTitleBar.svelteand evaluates it against a supplied environment, so the helper the gate now calls has to be supplied. It is passed the real function, so what that suite evaluates is still the shipped decision.Verification
The behaviour table above was measured in Chromium against the dev server, with
window.__TAURI_INTERNALS__stubbed so the frontend boots outside Tauri and everyinvokeis recorded. That proves dispatch and gating; it does not prove the PDF itself, sinceprint_pdfis answered by Rust — the export path underneath is unchanged and already covered byeditorPdfExport.test.tsandexportFoldParity.test.ts.Not verified: Windows and Linux. The chord is platform-independent here (
Modresolves per platform, and no branch is OS-specific), but nobody has pressed it there.