Skip to content

Add F5 shortcut key for Reload - #1922

Merged
emako merged 2 commits into
masterfrom
copilot/add-shortcut-key-reload
Apr 21, 2026
Merged

Add F5 shortcut key for Reload#1922
emako merged 2 commits into
masterfrom
copilot/add-shortcut-key-reload

Conversation

Copilot AI commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Previewing files that change on disk (e.g. Markdown) required closing and reopening the preview or clicking "Reload" from the More menu — no keyboard shortcut existed.

Changes

  • PipeServerManager.cs: Added PipeMessages.Reload constant; wired it to ViewWindowManager.ReloadPreview() in the message dispatcher
  • KeystrokeDispatcher.cs: Added Keys.F5 to the valid keys set; sends PipeMessages.Reload on keydown — consistent with F11 (fullscreen) handling
  • ViewerWindow.xaml: Added InputGestureText="F5" to the Reload menu item so the shortcut is discoverable via the More menu

Summary by Sourcery

Add support for reloading the current preview via an F5 keyboard shortcut and corresponding pipe message.

New Features:

  • Introduce a Reload pipe message that triggers reloading of the current preview window.
  • Enable F5 as a keyboard shortcut to send a reload command to the viewer.
  • Expose the F5 shortcut in the viewer UI by labeling the Reload menu item with the gesture text.

Copilot AI linked an issue Apr 21, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add shortcut key for reload functionality Add F5 shortcut key for Reload Apr 21, 2026
Copilot AI requested a review from emako April 21, 2026 11:00
@emako
emako marked this pull request as ready for review April 21, 2026 11:02
Copilot AI review requested due to automatic review settings April 21, 2026 11:02
@emako
emako merged commit 02fe066 into master Apr 21, 2026
3 checks passed
@sourcery-ai

sourcery-ai Bot commented Apr 21, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Implements an F5 keyboard shortcut to reload the preview by introducing a new pipe message, wiring it through the pipe server and keystroke dispatcher, and exposing the shortcut text in the Viewer UI menu.

Sequence diagram for F5 reload preview workflow

sequenceDiagram
    actor User
    participant KeystrokeDispatcher
    participant PipeServerManager
    participant ViewWindowManager

    User->>KeystrokeDispatcher: keydown F5
    KeystrokeDispatcher->>KeystrokeDispatcher: Validate key in _validKeys
    KeystrokeDispatcher->>PipeServerManager: SendMessage(PipeMessages.Reload)
    PipeServerManager->>PipeServerManager: MessageReceived(PipeMessages.Reload)
    PipeServerManager->>ViewWindowManager: GetInstance().ReloadPreview() via Dispatcher
    ViewWindowManager-->>User: Preview content reloaded
Loading

Class diagram for new F5 reload integration

classDiagram
    class PipeMessages {
        <<static>>
        +string Close
        +string Quit
        +string Fullscreen
        +string Reload
    }

    class PipeServerManager {
        +bool MessageReceived(string msg)
        +void Dispose()
        +static void SendMessage(string msg)
    }

    class KeystrokeDispatcher {
        -Keys[] _validKeys
        +void InvokeRoutine(Keys key, bool isKeyDown)
        +void Register()
        +void Unregister()
    }

    class ViewWindowManager {
        +static ViewWindowManager GetInstance()
        +void ReloadPreview()
    }

    PipeServerManager ..|> System_IDisposable

    KeystrokeDispatcher --> PipeServerManager : uses
    PipeServerManager --> PipeMessages : uses
    PipeServerManager --> ViewWindowManager : calls

    class System_IDisposable {
        <<interface>>
        +void Dispose()
    }
Loading

File-Level Changes

Change Details Files
Add a Reload pipe message and route it to the preview window reload logic.
  • Introduce a new PipeMessages.Reload constant alongside existing pipe message identifiers.
  • Handle the Reload pipe message in the MessageReceived dispatcher by invoking ViewWindowManager.ReloadPreview() on the application dispatcher with ApplicationIdle priority.
QuickLook/PipeServerManager.cs
Extend keystroke handling so F5 triggers a reload via the pipe messaging system.
  • Include Keys.F5 in the set of valid keys processed by the keystroke dispatcher.
  • Map the F5 keydown event to sending the PipeMessages.Reload message, analogous to existing F11 fullscreen handling.
QuickLook/KeystrokeDispatcher.cs
Expose the F5 shortcut in the Viewer UI so the reload gesture is discoverable.
  • Set InputGestureText="F5" on the Reload menu item in the Viewer’s XAML to display the shortcut in the More menu.
QuickLook/ViewerWindow.xaml

Assessment against linked issues

Issue Objective Addressed Explanation
#1921 Add a keyboard shortcut (F5) that triggers the existing "Reload/重新加载" action in the preview window so users can refresh the preview without closing/reopening or clicking the menu item.

Possibly linked issues

  • #: PR adds F5-triggered Reload behavior and menu hint, exactly implementing the requested reload shortcut feature.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an F5 keyboard shortcut to reload the currently open preview, making “Reload” accessible without using the UI menu.

Changes:

  • Added a new PipeMessages.Reload message and dispatched it to ViewWindowManager.ReloadPreview().
  • Updated global keystroke handling to treat F5 as a valid key and send the reload pipe message on keydown.
  • Updated the Viewer “More” context menu to display F5 as the Reload shortcut (InputGestureText).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
QuickLook/ViewerWindow.xaml Displays the Reload shortcut in the More menu for discoverability.
QuickLook/PipeServerManager.cs Defines and dispatches a new Reload pipe message to trigger preview reload on the UI thread.
QuickLook/KeystrokeDispatcher.cs Sends the Reload pipe message when F5 is pressed (global hook), consistent with existing F11 handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return false;

case PipeMessages.Reload:
Application.Current.Dispatcher.BeginInvoke(

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PipeServerManager uses _lastOperation to cancel pending dispatcher work for actions that can be triggered repeatedly (e.g., Invoke/Switch/Toggle). The new Reload handler schedules a dispatcher operation but does not assign it to _lastOperation, so repeated F5 presses can enqueue multiple reloads without cancellation, potentially causing unnecessary plugin reloads and UI churn. Consider assigning the BeginInvoke result to _lastOperation here (consistent with the other preview-changing cases) so subsequent pipe messages can abort a pending reload.

Suggested change
Application.Current.Dispatcher.BeginInvoke(
_lastOperation = Application.Current.Dispatcher.BeginInvoke(

Copilot uses AI. Check for mistakes.
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.

Hope to add a shortcut key for “重新加载"

3 participants