Skip to content

Feature: History context menu with delete & info item & Refactor context menu logic - #4609

Merged
Jack251970 merged 16 commits into
devfrom
feature/history-context-menu-delete
Aug 31, 2026
Merged

Feature: History context menu with delete & info item & Refactor context menu logic#4609
Jack251970 merged 16 commits into
devfrom
feature/history-context-menu-delete

Conversation

@Jack251970

@Jack251970 Jack251970 commented Aug 7, 2026

Copy link
Copy Markdown
Member
image

Summary by cubic

Adds a context menu for history items with Delete and Info, and refactors the context menu flow to be fully async and toggleable. Previously, history items had no context menu and Right Arrow only opened the menu for query results; now Right Arrow works for both, options are fuzzy-filtered by your query, window activation respects visibility, and returning restores your query, preview, and selection.

Summary of changes

  • Replaced LoadContextMenuCommand with ToggleContextMenuCommand, so the same command opens and closes the menu.
  • Esc closes the context menu and restores the previous results view, preview, query text, and reselects the targeted item, falling back to the prior index if the history list rebuilt.
  • Right Arrow opens the context menu when a result or history item is selected and the caret is at the end.
  • Context menu acts on the selected item, with history items handled via ContextData; returning restores the preview, and home results refresh after deletion.
  • Context menu entries are filtered by the fuzzy-search algorithm using the current query.
  • Flow is fully async: returning from the menu, changing query text, updating preview, and delete actions are awaited.
  • Consolidated context menu state (source, query, selection) into a single ResultsQuerySelection record.
  • Window activation checks visibility to avoid activating or focusing when the window is hidden.
  • Added: Delete and History Info options for history items, History.Remove(...) to delete a single entry or all matching entries (LastOpened style) with storage persisted, a delete icon asset with Constant.DeleteIcon, and title-case localization strings for the history labels.
  • Removed: the guard that blocked context menus for history results.
  • Memory impact: minimal, one record for context menu state and a single icon asset.
  • Security: no new inputs or elevated actions, only local history mutation.
  • Tests: added Flow.Launcher.Test/QueryHistoryTest.cs for single-entry and multi-entry removal across matching results.

Release Note
You can open a menu on history items to delete entries or view info, with options filtered by your query and your previous view restored after closing.

Written for commit bed0e19. Summary will update on new commits.

Review in cubic

TEST

  • Returning logic of context menu.
  • Deletion function of history items.

Implemented Remove method in QueryHistory to delete entries.
Added delete icon and context menu option in MainViewModel.
Updated Constant.cs for icon reference.
Added unit tests for single and multiple entry removal.
Remember and restore previous results view and query text when opening/closing the context menu. Add fields to track context menu state. Refactor context menu logic for regular/history results. Implement ReturnFromContextMenu() to centralize UI restoration. Update Esc command to close context menu and restore state. Improve context menu population and handle history result deletion with results refresh.
Added a "History Info" option to the history item context menu in MainViewModel. The new ContextMenuHistoryInfo method creates this entry, allowing users to view information about a history item. The menu now includes both "Delete History" and "History Info" options.
The context menu now loads when a history item is selected and the caret is at the end of the text box, in addition to query results. Made HistorySelected internal in MainViewModel.cs to enable this behavior from MainWindow.xaml.cs.
Copilot AI lite review requested due to automatic review settings August 7, 2026 08:29
@github-actions github-actions Bot added this to the 2.2.0 milestone Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change adds history-entry removal, history-specific context-menu actions, and context restoration. Right Arrow opens context menus for history selections when the caret is at the query end. Escape returns from context menus before changing views or hiding the launcher.

Changes

History context-menu flow

Layer / File(s) Summary
History removal contract and tests
Flow.Launcher/Storage/QueryHistory.cs, Flow.Launcher.Test/QueryHistoryTest.cs
History.Remove supports single-entry removal and removal of matching entries. Tests verify removal counts and remaining entries.
Context-menu state and navigation
Flow.Launcher/ViewModel/MainViewModel.cs, Flow.Launcher/MainWindow.xaml.cs
Context-menu navigation preserves the source view, query, selected result, and history item. Right Arrow and Escape handle history context menus.
History menu actions and persistence
Flow.Launcher/ViewModel/MainViewModel.cs, Flow.Launcher.Infrastructure/Constant.cs
History results expose delete and history-information actions. Deletion saves changed history and refreshes the appropriate view.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: jjw24, taooceros

Sequence Diagram(s)

sequenceDiagram
  participant MainWindow
  participant MainViewModel
  participant History
  MainWindow->>MainViewModel: Open context menu for selected history result
  MainViewModel->>History: Remove history item
  History-->>MainViewModel: Return removal count
  MainViewModel->>History: Save updated history
  MainViewModel-->>MainWindow: Restore source view and refresh results
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the history context-menu feature and the related context-menu refactor.
Description check ✅ Passed The description directly explains the history context-menu actions, navigation refactor, deletion behavior, and tests.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/history-context-menu-delete

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Jack251970 Jack251970 removed this from the 2.2.0 milestone Aug 7, 2026

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

This PR enhances Flow Launcher’s history UX by adding a dedicated context menu for history results (with delete and info actions) and refactors context menu navigation so users can reliably return to the prior results view (query results vs. history) after interacting with the context menu.

Changes:

  • Added deletion support for history entries via History.Remove(...) and surfaced it as a “Delete” context menu item for history results.
  • Refactored context menu flow to preserve/restore the originating results view and target item for context menu generation.
  • Added unit tests covering single-entry and “remove all matching” deletion behavior; added a DeleteIcon constant for UI usage.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Flow.Launcher/ViewModel/MainViewModel.cs Refactors context menu navigation, adds history context menu items (delete/info), and wires deletion + UI refresh behavior.
Flow.Launcher/Storage/QueryHistory.cs Adds History.Remove(...) to support deleting individual history entries or all matching entries.
Flow.Launcher/MainWindow.xaml.cs Enables opening context menu from the history view via keyboard (Right arrow).
Flow.Launcher.Test/QueryHistoryTest.cs Adds unit tests for the new history removal behavior.
Flow.Launcher.Infrastructure/Constant.cs Introduces DeleteIcon path for the new context menu item icon.
Suppressed comments (1)

Flow.Launcher/ViewModel/MainViewModel.cs:1894

  • The lambda parameter in the delete-history context menu action is unused. Using _ => makes this explicit and avoids unused-parameter warnings from analyzers.
                    OriginQuery = result.OriginQuery
                };

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

@Jack251970 Jack251970 added enhancement New feature or request Code Refactor labels Aug 7, 2026
@Jack251970
Jack251970 marked this pull request as draft August 7, 2026 08:35
Jack251970 and others added 2 commits August 7, 2026 16:35
Refactored ReturnFromContextMenu to ReturnFromContextMenuAsync and updated all call sites to use await. Related methods like ChangeQueryText and UpdatePreviewAsync are now awaited. Updated context menu delete action to use an async lambda, ensuring UI and data updates complete asynchronously before proceeding.

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

Copilot reviewed 5 out of 6 changed files in this pull request and generated no new comments.

Suppressed comments (1)

Flow.Launcher/ViewModel/MainViewModel.cs:1355

  • History context menus return before applying the context-menu query filter. As a result, typing while this menu is open always leaves both Delete and Info visible, whereas regular context-menu items are filtered below. Filter these history actions with query before adding them.
                ContextMenu.AddResults([
                    ContextMenuDeleteHistory(historyItem),
                    ContextMenuHistoryInfo(historyItem)
                ], id);

@Jack251970
Jack251970 marked this pull request as ready for review August 10, 2026 03:22
Refactored Dispatcher.BeginInvoke usage to an async lambda that checks window visibility before calling Activate() and focusing QueryTextBox. This prevents activation and focus when the window is not visible.

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread Flow.Launcher/ViewModel/MainViewModel.cs Outdated
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 1 file (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread Flow.Launcher/ViewModel/MainViewModel.cs
Comment thread Flow.Launcher/ViewModel/MainViewModel.cs
@Jack251970

Copy link
Copy Markdown
Member Author

@codex Review it

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e350dc23b8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Flow.Launcher/ViewModel/MainViewModel.cs
@Jack251970 Jack251970 added this to the 2.2.0 milestone Aug 13, 2026
Introduce _contextMenuTargetIndex to track selected result index when opening context menu. Restore selection to the targeted result or fallback to previous index after returning. Add ResultEqual helper for result comparison. Reset context menu tracking fields after use.
@Jack251970
Jack251970 requested a balanced review from Copilot August 13, 2026 01:12
@Jack251970

Copy link
Copy Markdown
Member Author

@codex Review it

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

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

Suppressed comments (1)

Flow.Launcher/ViewModel/MainViewModel.cs:446

  • The new context-menu return state machine is untested. The added QueryHistoryTest only covers History.Remove, so regressions in restoring the Results/History source, query text, selected target/fallback index, and preview would not be caught. Add focused tests for returning via Esc and after deletion from both source views.
        private async Task ReturnFromContextMenuAsync()

Comment thread Flow.Launcher/MainWindow.xaml.cs

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2dc41eee79

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Flow.Launcher/ViewModel/MainViewModel.cs

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 1 file (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread Flow.Launcher/ViewModel/MainViewModel.cs
@Jack251970
Jack251970 requested a review from DavidGBrett August 17, 2026 09:47
Comment on lines +1993 to +2004
private Result ContextMenuHistoryInfo(LastOpenedHistoryResult historyItem)
{
return new Result
{
Title = Settings.HistoryStyle == HistoryStyle.Query ? Localize.queryHistory() : Localize.executedHistory(),
IcoPath = Constant.HistoryIcon,
Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\uE81C"),
PluginDirectory = Constant.ProgramDirectory,
Action = _ => false,
OriginQuery = historyItem.OriginQuery
};
}

@DavidGBrett DavidGBrett Aug 18, 2026

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.

What is the intention of this context menu result?
It looks to do nothing to me...
Perhaps we could change the name or add comments to make this clearer

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What is the intention of this context menu result? It looks to do nothing to me... Perhaps we could change the name or add comments to make this clearer

Here I want to add the result info items as the plugin info items of other items. I know this could be little useless, but I want to make this behaviour consistent with the items from other plugins.

@DavidGBrett DavidGBrett Aug 30, 2026

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.

Ok I see,
I added a comment above to make it's purpose a little clearer.

Comment thread Flow.Launcher/ViewModel/MainViewModel.cs Outdated
Comment thread Flow.Launcher/ViewModel/MainViewModel.cs Outdated
Comment thread Flow.Launcher/ViewModel/MainViewModel.cs Outdated
Comment thread Flow.Launcher/ViewModel/MainViewModel.cs Outdated
Jack251970 and others added 3 commits August 30, 2026 13:58
ToggleContextMenuCommand now toggles context menu state, replacing all usages of LoadContextMenuCommand in XAML and ViewModel. Updated key bindings and command references in MainWindow.xaml and MainViewModel.cs. Replaced LoadContextMenuAsync with ToggleContextMenuAsync to handle both opening and closing the context menu.
Replaced multiple context menu state fields in MainViewModel with a sealed ResultsQuerySelection record. This encapsulates source, query text, selected result, and index, simplifying state management and improving maintainability. Updated all related logic to use the new structure.
@Jack251970

Copy link
Copy Markdown
Member Author

@DavidGBrett Hi, thanks for your comments! I have polished my codes to meet your suggestions and they works for me. Could you please check if they meet your ideas and work correctly? Also please help me confirm if #4626 is resolved. I cannot reproduce this issue on my side.

Clarified that this result method exists to label the history context menu and say what the history style is.
This better matches the existing plugin context menu labels

@DavidGBrett DavidGBrett 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.

Thank you for your work on this!
Looks clearer now and I can confirm it works!

That issue looks to be resolved, though I thought it was pre-existing - at least I can't replicate it either now

@Jack251970
Jack251970 merged commit 9c1f74e into dev Aug 31, 2026
4 checks passed
@Jack251970
Jack251970 deleted the feature/history-context-menu-delete branch August 31, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code Refactor enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Returning from history menu sets selected result to first one after brief delay

3 participants