Skip to content

Support Preview Panel for History Results #3370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Mar 26, 2025

Conversation

Jack251970
Copy link
Contributor

@Jack251970 Jack251970 commented Mar 22, 2025

Support Preview Panel for History Results

image

TODO

  • When selected items are from history, the preview panel height is 0.
  • History item preview image cannot be loaded.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Jack251970 Jack251970 added enhancement New feature or request kind/ui related to UI, icons, themes, etc labels Mar 25, 2025

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Jack251970 Jack251970 marked this pull request as ready for review March 26, 2025 02:44
@Jack251970 Jack251970 requested a review from onesounds March 26, 2025 02:45
Copy link

gitstream-cm bot commented Mar 26, 2025

🥷 Code experts: onesounds

onesounds, Jack251970 have most 👩‍💻 activity in the files.
onesounds, Jack251970 have most 🧠 knowledge in the files.

See details

Flow.Launcher.Infrastructure/Constant.cs

Activity based on git-commit:

onesounds Jack251970
MAR
FEB
JAN 3 additions & 1 deletions
DEC 2 additions & 1 deletions
NOV
OCT

Knowledge based on git-blame:
onesounds: 9%
Jack251970: 5%

Flow.Launcher/MainWindow.xaml

Activity based on git-commit:

onesounds Jack251970
MAR 5 additions & 6 deletions
FEB 1 additions & 1 deletions
JAN
DEC
NOV 1 additions & 1 deletions
OCT

Knowledge based on git-blame:
onesounds: 89%
Jack251970: 1%

Flow.Launcher/MainWindow.xaml.cs

Activity based on git-commit:

onesounds Jack251970
MAR 310 additions & 120 deletions 637 additions & 699 deletions
FEB 8 additions & 4 deletions 1 additions & 1 deletions
JAN
DEC 5 additions & 10 deletions
NOV
OCT

Knowledge based on git-blame:
Jack251970: 52%
onesounds: 24%

Flow.Launcher/Themes/Base.xaml

Activity based on git-commit:

onesounds Jack251970
MAR 34 additions & 49 deletions
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
onesounds: 67%

Flow.Launcher/ViewModel/MainViewModel.cs

Activity based on git-commit:

onesounds Jack251970
MAR 236 additions & 183 deletions 119 additions & 171 deletions
FEB 23 additions & 25 deletions 63 additions & 21 deletions
JAN 17 additions & 21 deletions
DEC 59 additions & 63 deletions
NOV 39 additions & 15 deletions
OCT

Knowledge based on git-blame:
onesounds: 14%
Jack251970: 12%

Flow.Launcher/ViewModel/ResultViewModel.cs

Activity based on git-commit:

onesounds Jack251970
MAR
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
onesounds: 1%

Flow.Launcher/ViewModel/ResultsViewModel.cs

Activity based on git-commit:

onesounds Jack251970
MAR
FEB
JAN
DEC
NOV
OCT

Knowledge based on git-blame:
onesounds: 5%

To learn more about /:\ gitStream - Visit our Docs

Copy link

gitstream-cm bot commented Mar 26, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

coderabbitai bot commented Mar 26, 2025

📝 Walkthrough

Walkthrough

The pull request introduces multiple enhancements and refactorings. A new constant (HistoryIcon) is added to provide an image path. The XAML files are updated with explicit element names and adjusted data bindings to improve UI element references and visibility triggers. Key event handling in the MainWindow code-behind now calls a renamed method for determining query selection. The MainViewModel and related ViewModel files see asynchronous method refactoring, renaming, and property updates to better handle preview functionality, while ResultViewModel and ResultsViewModel receive naming and formatting improvements for clarity and consistency.

Changes

File(s) Changes Summary
Flow.Launcher.Infrastructure/Constant.cs Added public static readonly string HistoryIcon with a path to "history.png".
Flow.Launcher/MainWindow.xaml
Flow.Launcher/Themes/Base.xaml
Added x:Name attributes (e.g., QueryBoxArea, MiddleSeparatorArea, ResultPreviewArea), updated DataContext bindings, and adjusted MultiDataTrigger conditions.
Flow.Launcher/MainWindow.xaml.cs Replaced _viewModel.SelectedIsFromQueryResults() with _viewModel.QueryResultsSelected() in key event handling.
Flow.Launcher/ViewModel/MainViewModel.cs Renamed SelectedIsFromQueryResults to QueryResultsSelected, introduced PreviewSelectedItem, added QueryResultsPreviewed(), and refactored preview update methods to asynchronous versions.
Flow.Launcher/ViewModel/ResultViewModel.cs Renamed font variables and fields (e.g., _imageLoaded, _image, etc.) to follow a consistent naming convention and simplified preview image loading logic.
Flow.Launcher/ViewModel/ResultsViewModel.cs Reordered using directives, adjusted blank lines, and simplified pattern matching for property change logic, enhancing readability.

Sequence Diagram(s)

sequenceDiagram
    participant UI as MainWindow (UI)
    participant VM as MainViewModel
    participant DataBinding as DataContext

    UI->>VM: OnKeyDown(event)
    VM->>VM: QueryResultsSelected()
    alt Query results are selected
        VM->>VM: UpdatePreviewAsync()
        VM->>VM: ShowPreviewAsync()
        VM->>DataBinding: Update PreviewSelectedItem
    else Alternate key action
        VM->>VM: Execute Escape/Backspace command
    end
Loading

Suggested labels

bug

Suggested reviewers

  • taooceros

Poem

I'm just a rabbit, hopping in code's glen,
New icons and async flows make joy again.
Fields renamed and XAML named with care,
In every change, a soft code affair.
With each refactor, I wink and declare 🐰✨!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d73980a and 65f07d8.

📒 Files selected for processing (2)
  • Flow.Launcher/MainWindow.xaml (7 hunks)
  • Flow.Launcher/Themes/Base.xaml (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • Flow.Launcher/Themes/Base.xaml
  • Flow.Launcher/MainWindow.xaml
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (9)
Flow.Launcher/ViewModel/MainViewModel.cs (9)

52-53: Consider using Array.Empty<Result>() for _emptyResult.

Storing an empty List<Result> is fine, but using Array.Empty<Result>() avoids extra allocations and may simplify code.

-private readonly IReadOnlyList<Result> _emptyResult = new List<Result>();
+private readonly IReadOnlyList<Result> _emptyResult = Array.Empty<Result>();

167-173: Async call in property change without error handling.

When the Results.SelectedItem changes, _ = UpdatePreviewAsync() is invoked. Consider capturing the returned task, adding logging, or using a safe fire-and-forget pattern to handle possible exceptions instead of discarding them.

- _ = UpdatePreviewAsync();
+ var previewTask = UpdatePreviewAsync();
// e.g. add logging or .ContinueWith(...) to handle errors

174-181: Mirroring logic for History.PropertyChanged.

Here as well, _ = UpdatePreviewAsync() is used. Apply similar exception handling measures as recommended for Results changes to maintain consistent error handling across the codebase.


874-902: ShowPreviewAsync() method introduced for asynchronous handling.

Transitioning from sync to async improves responsiveness. However, consider capturing the task returned by OpenExternalPreviewAsync or using a safe pattern to handle failures (instead of _ =).


979-979: Switching external preview asynchronously.

Again, consider storing the task or handling errors from _ = SwitchExternalPreviewAsync(...).


984-984: Open external preview from HideInternalPreview.

Double-check that external preview’s success/failure is logged or handled to prevent silent failures.


997-997: Load the preview image if internal preview is visible.

Straightforward approach. Confirm performance if preview images can be large or frequently changed.


1468-1468: Awaiting CloseExternalPreviewAsync() in Hide().

Prevents leaving an external preview open. This is good. Consider a short comment or log if the method fails.


1481-1481: Force UI update after resetting query text.

Explicitly calling UpdateLayout() is occasionally brittle, but if needed for immediate refresh, this is acceptable. Review possible performance impact.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 298af4d and d73980a.

📒 Files selected for processing (7)
  • Flow.Launcher.Infrastructure/Constant.cs (1 hunks)
  • Flow.Launcher/MainWindow.xaml (5 hunks)
  • Flow.Launcher/MainWindow.xaml.cs (3 hunks)
  • Flow.Launcher/Themes/Base.xaml (1 hunks)
  • Flow.Launcher/ViewModel/MainViewModel.cs (25 hunks)
  • Flow.Launcher/ViewModel/ResultViewModel.cs (9 hunks)
  • Flow.Launcher/ViewModel/ResultsViewModel.cs (7 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
Flow.Launcher/MainWindow.xaml.cs (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)
  • QueryResultsSelected (1386-1390)
Flow.Launcher/ViewModel/ResultViewModel.cs (1)
Flow.Launcher/ViewModel/MainViewModel.cs (2)
  • Result (1318-1356)
  • Result (1358-1384)
Flow.Launcher/ViewModel/MainViewModel.cs (5)
Flow.Launcher/PublicAPIInstance.cs (6)
  • List (160-160)
  • Task (94-94)
  • Task (165-165)
  • Task (167-168)
  • Task (170-171)
  • Task (346-346)
Flow.Launcher/ViewModel/ResultsViewModel.cs (2)
  • List (218-229)
  • List (231-240)
Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs (1)
  • List (146-149)
Flow.Launcher/ViewModel/ResultViewModel.cs (2)
  • ResultViewModel (15-274)
  • ResultViewModel (20-62)
Flow.Launcher/MainWindow.xaml.cs (3)
  • Task (580-587)
  • MainWindow (30-998)
  • MainWindow (65-77)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (33)
Flow.Launcher/Themes/Base.xaml (1)

453-454: Good fix for the preview panel visibility when viewing history items.

This change properly activates the condition that checks the History element's visibility, moving it outside the comment block. Now when history items are selected, the preview panel height won't be incorrectly set to 0, which directly addresses the first goal mentioned in the PR objectives.

Flow.Launcher/ViewModel/ResultsViewModel.cs (3)

11-12: Improved code organization.

The reorganization of using directives enhances code organization by grouping related imports together.


31-31: Improved code readability.

The addition of blank lines between logical sections improves code readability by visually separating related code blocks.

Also applies to: 241-241, 272-272, 300-300, 312-312


263-263: Modern C# pattern matching usage.

Using pattern matching with is not operator is more concise and less error-prone than a separate cast and null check.

Flow.Launcher/ViewModel/ResultViewModel.cs (6)

17-18: Improved naming conventions and immutability.

Good improvement using PascalCase for static readonly fields and adding the readonly modifier to ensure collection immutability.


143-147: Consistent private field naming convention.

The renaming of private fields to use the underscore prefix (_imageLoaded, _previewImageLoaded, etc.) improves code consistency and follows standard C# naming conventions.


24-25: Simplified control flow.

Removing unnecessary braces and whitespace makes the code more concise while maintaining readability.

Also applies to: 98-99, 108-109


40-45: More efficient dictionary lookup.

Using TryGetValue instead of checking for key existence followed by accessing the value is more efficient as it performs a single dictionary lookup instead of two.


164-177: Robust preview image handling.

The expanded PreviewImage property now properly checks if the preview image is loaded before triggering an asynchronous load, which addresses the issue with preview images for history items not loading correctly.


237-241: Improved condition check for preview image loading.

The combined condition now properly checks if the default preview is visible, if the preview image hasn't been loaded yet, and if the preview image should be shown, which helps fix the issue with preview images for history items.

Flow.Launcher.Infrastructure/Constant.cs (1)

35-35: Added resource path for history icon.

Adding the HistoryIcon constant provides a centralized reference to the history icon image, supporting the display of history items in the preview panel.

Flow.Launcher/MainWindow.xaml.cs (1)

304-312: Improved method naming for clarity.

Renaming SelectedIsFromQueryResults() to QueryResultsSelected() makes the code more readable and better describes the method's purpose: checking if the currently selected items are from query results rather than history results.

This change, combined with the other modifications, helps address the issue where the preview panel height was set to 0 when selected items were from history by making the distinction between query results and history items clearer.

Also applies to: 314-320, 324-336

Flow.Launcher/MainWindow.xaml (5)

218-218: Confirm consistent naming conventions for new Grid.

Good practice to name this grid for reference, but please ensure that it aligns with existing naming patterns and style guidelines in the project (e.g., camelCase vs. PascalCase, suffix “Area” for Grids, etc.).


341-341: Grid naming for MiddleSeparatorArea looks consistent.

The new x:Name property improves clarity and likely supports referencing in code-behind or triggers. No concerns with this approach.


381-381: ResultPreviewArea naming is clear and descriptive.

Naming the border makes referencing the preview area straightforward. Looks good.


444-444: DataContext bound to PreviewSelectedItem in internal preview area.

Switching from SelectedItem to PreviewSelectedItem (with one-way binding) makes sense for a read-only preview context. Ensure any necessary updates to PreviewSelectedItem are triggered in your ViewModel so the UI refreshes properly.


521-521: Second DataContext change to PreviewSelectedItem.

Same rationale as above. One-way binding is appropriate if the preview is read-only. No issues here.

Flow.Launcher/ViewModel/MainViewModel.cs (16)

284-284: LoadHistory uses if (QueryResultsSelected()).

This condition likely toggles to history view only from query results. The logic looks correct, but verify if the intent is to allow flipping from other states (like context menu) as well.


298-298: Only re-query when in query results.

Ensures that pressing ReQuery does not interfere when in history or context menu states. This is consistent, but confirm no user scenarios are missed if called from other states.


369-369: Autocomplete query restricted to query results.

if (result != null && QueryResultsSelected()) is a fair approach to avoid autocompletion in other views. No issues here.


421-421: Storing user selection only when query results are selected.

Updates _userSelectedRecord and _history only if in query results. This maintains logical consistency, preventing polluting the record with context menu selections. LGTM.


500-500: SelectPrevItem also checks QueryResultsSelected().

Ensures that pressing a navigation hotkey does not incorrectly manipulate the history state. Looks consistent with your new logic.


520-520: ESC action: fallback to query results if not currently there.

This is consistent with typical WPF flow: returning to main results or hiding the window. No concerns.


532-532: BackToQueryResults method checks QueryResultsSelected().

Ensures we only toggle back if we're not already in query results. Straightforward logic.


834-836: Introduce constants for preview area columns.

ResultAreaColumnPreviewShown = 1, ResultAreaColumnPreviewHidden = 3. This clarifies the layout logic. Good practice to use named constants.


837-849: New _selectedItemFromQueryResults tracking & PreviewSelectedItem.

Storing a nullable bool to track whether the selection originates from query results is helpful for UI logic. PreviewSelectedItem property looks properly implemented with OnPropertyChanged().


893-894: Close external preview then show internal preview.

Sequential calls are correct, but verify that calling CloseExternalPreviewAsync back-to-back with ShowInternalPreview does not cause flicker or concurrency issues.


991-991: Close external preview if it’s visible.

Ensure cancellation tokens or re-entrant calls won’t cause race conditions here.


1004-1004: Use QueryResultsPreviewed() to select the correct file path.

This logic is simple and direct. Verify that other states (e.g. from history or context menu) don’t incorrectly remain empty.


1008-1012: QueryResultsPreviewed() method clarifies the preview origin condition.

This is a clear helper to ensure the currently previewed item is from Results.SelectedItem.


1019-1019: Include re-query only if we’re in query results.

Consistent with your updated architecture. No blockers.


1420-1426: ShouldIgnoreHotkeys method introduced.

Checks full-screen or game mode. This is a neat way to unify condition checks. Ensure logic is tested on multi-monitor setups where foreground app detection might vary.


1471-1471: Fallback to query results before hiding.

Ensures consistency in final UI state.

@taooceros
Copy link
Member

Looks cool, but I am wondering why is this needed?

@Jack251970
Copy link
Contributor Author

Looks cool, but I am wondering why is this needed?

Since context menu will not hide preview panel, we should also provide preview panel for history records

@Jack251970
Copy link
Contributor Author

Or you will get this if you enable preview panel:
image

@taooceros
Copy link
Member

I see, better than empty

@taooceros
Copy link
Member

Looks cool, but I am wondering why is this needed?

Since context menu will not hide preview panel, we should also provide preview panel for history records

It's a bit different. ContextMenu's results are provided by plugins, which may include a special preview (I don't know whether anyone do that though).

taooceros
taooceros previously approved these changes Mar 26, 2025
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 24
⚠️ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

Forbidden patterns 🙅 (1)

In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves.

These forbidden patterns matched content:

s.b. workaround(s)

\bwork[- ]arounds?\b
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@Jack251970 Jack251970 added this to the 1.20.0 milestone Mar 26, 2025
@Jack251970 Jack251970 merged commit 350276d into Flow-Launcher:dev Mar 26, 2025
4 checks passed
@jjw24 jjw24 added bug Something isn't working and removed enhancement New feature or request labels Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working kind/ui related to UI, icons, themes, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants