Skip to content

Fix last opened result not showing in 'Empty Last Query' mode#4375

Merged
jjw24 merged 3 commits intodevfrom
fix_last_result_not_showing
Mar 24, 2026
Merged

Fix last opened result not showing in 'Empty Last Query' mode#4375
jjw24 merged 3 commits intodevfrom
fix_last_result_not_showing

Conversation

@jjw24
Copy link
Copy Markdown
Member

@jjw24 jjw24 commented Mar 23, 2026

Fix last opened result not showing in 'Empty Last Query' query style mode after result is selected, and would only show when re-queried or clearing of a new query.

The cause is the Hide() call after result is actioned triggers a QueryResultsAsync which constructs the result list before the result is added to the last opened history items.

Closing #4374


Summary by cubic

Fixes the bug where the last opened result didn’t appear in history in “Empty Last Query” mode by recording history before hiding the window. Keeps the window visible for Dialog Jump left-click to keep navigation smooth.

Summary of changes

  • Changed: Write history before any Hide(); consolidated Dialog Jump left-click check into isDialogJumpLeftClick; reuse a local hideWindow flag; move user-ranking record after the conditional Hide().
  • Added: Conditional Hide() executed only after history write and only for normal query results (not Dialog Jump left-click).
  • Removed: Immediate Hide() after ExecuteAsync; hiding is now deferred and conditional.
  • Misc: Clarified inline comments; fixed a minor typo.
  • Memory impact: None; only simple locals added.
  • Security risks: None; control flow only with no new I/O or privileges.
  • Unit tests: No new tests; manual checks for “Empty Last Query” and Dialog Jump left-click paths.

Written for commit 654026e. Summary will update on new commits.

@jjw24 jjw24 added the Dev branch only An issue or fix for the Dev branch build label Mar 23, 2026
@prlabeler prlabeler bot added the bug Something isn't working label Mar 23, 2026
@github-actions github-actions bot added this to the 2.2.0 milestone Mar 23, 2026
@jjw24 jjw24 marked this pull request as ready for review March 24, 2026 09:54
@jjw24 jjw24 removed the bug Something isn't working label Mar 24, 2026
@jjw24 jjw24 linked an issue Mar 24, 2026 that may be closed by this pull request
3 tasks
@gitstream-cm
Copy link
Copy Markdown

gitstream-cm bot commented Mar 24, 2026

🥷 Code experts: Jack251970

Jack251970 has most 👩‍💻 activity in the files.
Jack251970 has most 🧠 knowledge in the files.

See details

Flow.Launcher/ViewModel/MainViewModel.cs

Activity based on git-commit:

Jack251970
MAR
FEB 11 additions & 6 deletions
JAN 50 additions & 35 deletions
DEC
NOV 106 additions & 94 deletions
OCT 2419 additions & 88 deletions

Knowledge based on git-blame:
Jack251970: 95%

✨ Comment /gs review for LinearB AI review. Learn how to automate it here.

@gitstream-cm
Copy link
Copy Markdown

gitstream-cm bot commented Mar 24, 2026

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

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@prlabeler prlabeler bot added the bug Something isn't working label Mar 24, 2026
@coderabbitai coderabbitai bot removed the bug Something isn't working label Mar 24, 2026
@jjw24 jjw24 requested a review from Copilot March 24, 2026 09:56
@jjw24
Copy link
Copy Markdown
Member Author

jjw24 commented Mar 24, 2026

@coderabbitai full review.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

@jjw24 Sure! I'll redo the full review of the PR now.


🧠 Learnings used
Learnt from: jjw24
Repo: Flow-Launcher/Flow.Launcher PR: 4057
File: Flow.Launcher/Storage/LastOpenedHistoryResult.cs:35-56
Timestamp: 2026-01-05T10:06:46.190Z
Learning: In Flow.Launcher/Storage/LastOpenedHistoryResult.cs, the LastOpenedHistoryResult(Result result) constructor should not add null checks for result or result.OriginQuery - the maintainer prefers fail-fast behavior where invalid inputs cause immediate exceptions.
✅ Actions performed

Full review triggered.

@jjw24 jjw24 enabled auto-merge (squash) March 24, 2026 09:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a timing issue in MainViewModel.OpenResultAsync where calling Hide() could trigger a re-query before the selected result was added to “last opened” history, causing the item to be missing in “Empty Last Query” mode (issue #4374).

Changes:

  • Reorders OpenResultAsync to add selected results to history before conditionally calling Hide().
  • Consolidates the Dialog Jump left-click condition into a single local (isDialogJumpLeftClick) and defers Hide() until after history update.
  • Makes the hide behavior conditional so Dialog Jump left-click navigation doesn’t trigger a hide path.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

Reordered MainViewModel result-open flow: introduced isDialogJumpLeftClick, deferred/hopped window hiding to after history/record updates, assigned ExecuteAsync(...) result to hideWindow, and prevented Hide() for Dialog Jump left-click even if execution returns true.

Changes

Cohort / File(s) Summary
Query Execution Flow Reordering
Flow.Launcher/ViewModel/MainViewModel.cs
Extracted isDialogJumpLeftClick, assigned ExecuteAsync(...) return to hideWindow, moved history/user-selected-record updates earlier, deferred Hide() and changed condition to !isDialogJumpLeftClick && hideWindow so Dialog Jump left-clicks no longer hide the window.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • Jack251970
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and accurately describes the main bug fix: last opened result not showing in 'Empty Last Query' mode, which aligns with the core change of reordering hide() logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description clearly describes the bug being fixed and explains the root cause, relating directly to the changeset's reordering of history recording before window hiding.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix_last_result_not_showing

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 and usage tips.

Copy link
Copy Markdown
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Flow.Launcher/ViewModel/MainViewModel.cs`:
- Around line 553-560: Move the call to _userSelectedRecord.Add(result) to occur
before calling Hide() because Hide() can trigger an immediate, asynchronous
re-query (in LastQueryMode.Empty and LastQueryMode.ActionKeyword*), and
UpdateResultView() reads _userSelectedRecord to score rebuilt results; change
the ordering in MainViewModel so _userSelectedRecord.Add(result) executes prior
to Hide() to avoid a race that can reopen with stale ranking.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 752a9fbf-49b1-4ef9-b64f-09defc641606

📥 Commits

Reviewing files that changed from the base of the PR and between de36eaf and 4a8dd26.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@prlabeler prlabeler bot added the bug Something isn't working label Mar 24, 2026
@coderabbitai coderabbitai bot removed the bug Something isn't working label Mar 24, 2026
@jjw24 jjw24 requested a review from Jack251970 March 24, 2026 10:08
Copy link
Copy Markdown
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.

♻️ Duplicate comments (1)
Flow.Launcher/ViewModel/MainViewModel.cs (1)

553-560: ⚠️ Potential issue | 🟡 Minor

Move _userSelectedRecord.Add(result) before Hide() too.

Hide() is fire-and-forget here and can immediately re-query in LastQueryMode.Empty and LastQueryMode.ActionKeyword*. UpdateResultView() then reads _userSelectedRecord on Lines 2302-2311 while rescoring rebuilt results, so this can still reopen with stale ranking even though the history write is now ordered correctly.

🔧 Suggested ordering
             if (queryResultsSelected)
             {
                 _history.Add(result);
                 lastHistoryIndex = 1;
             }
 
+            // Record user selected result for result ranking before any hide-triggered requery.
+            _userSelectedRecord.Add(result);
+
             // Only hide for query results (not Dialog Jump left-click mode)
             if (!isDialogJumpLeftClick && hideWindow)
             {
                 Hide();
             }
-
-            // Record user selected result for result ranking
-            _userSelectedRecord.Add(result);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Flow.Launcher/ViewModel/MainViewModel.cs` around lines 553 - 560, Move the
call that records the user selection so it executes before the asynchronous
Hide() call: change the ordering in the click-handling block so
_userSelectedRecord.Add(result) runs before calling Hide(), ensuring
UpdateResultView() (which reads _userSelectedRecord during rescoring for
LastQueryMode.Empty and LastQueryMode.ActionKeyword*) sees the new record;
update the code around the current Hide()/_userSelectedRecord.Add(result) pair
in MainViewModel (the click/result selection handling method) so the history
write happens synchronously prior to invoking Hide().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@Flow.Launcher/ViewModel/MainViewModel.cs`:
- Around line 553-560: Move the call that records the user selection so it
executes before the asynchronous Hide() call: change the ordering in the
click-handling block so _userSelectedRecord.Add(result) runs before calling
Hide(), ensuring UpdateResultView() (which reads _userSelectedRecord during
rescoring for LastQueryMode.Empty and LastQueryMode.ActionKeyword*) sees the new
record; update the code around the current
Hide()/_userSelectedRecord.Add(result) pair in MainViewModel (the click/result
selection handling method) so the history write happens synchronously prior to
invoking Hide().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 61b673b3-0165-4712-8531-53d8a33a5e54

📥 Commits

Reviewing files that changed from the base of the PR and between 4a8dd26 and 654026e.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/MainViewModel.cs

Copy link
Copy Markdown
Member

@Jack251970 Jack251970 left a comment

Choose a reason for hiding this comment

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

LGTM!

@jjw24 jjw24 merged commit eefac8f into dev Mar 24, 2026
20 checks passed
@jjw24 jjw24 deleted the fix_last_result_not_showing branch March 24, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dev branch only An issue or fix for the Dev branch build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dev: Last history result not showing for 'Empty Last Query' query style

3 participants