Skip to content

[Peek] Fix Space key triggering during file rename (#44845)#44995

Merged
vanzue merged 1 commit intomainfrom
issue/44845
Jan 26, 2026
Merged

[Peek] Fix Space key triggering during file rename (#44845)#44995
vanzue merged 1 commit intomainfrom
issue/44845

Conversation

@yeelam-gordon
Copy link
Copy Markdown
Contributor

Don't show error window when CurrentItem is null - just return silently. This restores the original behavior where CaretVisible() detection in GetSelectedItems() would suppress Peek by returning null, and no window would be shown.

PR #44703 added an error window for virtual folders (Home/Recent), but this also triggered when user was typing (rename, search, address bar), stealing focus and cancelling the operation.

Fixes #44845

Summary of the Pull Request

Don't show error window when CurrentItem is null - just return silently.
This restores the original behavior where CaretVisible() detection in
GetSelectedItems() would suppress Peek by returning null, and no window
would be shown.

PR #44703 added an error window for virtual folders (Home/Recent), but
this also triggered when user was typing (rename, search, address bar),
stealing focus and cancelling the operation.

Fixes #44845
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

Adjusts Peek’s activation flow so it no longer shows an error window when no item is selected (e.g., during in-place rename / search typing), preventing focus-stealing that cancels the user’s operation.

Changes:

  • Stops showing the “No files selected…” error UI when ViewModel.CurrentItem is null.
  • Returns silently from initialization when no preview item is available.

// If no files were found (e.g., user is typing in rename/search box, or in virtual folders),
// don't show anything - just return silently to avoid stealing focus
if (ViewModel.CurrentItem == null)
{
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

Returning early when ViewModel.CurrentItem is null leaves the window in whatever state it was in. In particular, the first activation path calls Activate() before Initialize(), so this branch can still result in an activated/visible (but empty) Peek window and focus being stolen. Consider explicitly hiding/uninitializing the window in this branch, or restructuring so the window is only activated/shown once a non-null CurrentItem is confirmed.

Suggested change
{
{
Uninitialize();

Copilot uses AI. Check for mistakes.
Comment on lines +200 to 205
// If no files were found (e.g., user is typing in rename/search box, or in virtual folders),
// don't show anything - just return silently to avoid stealing focus
if (ViewModel.CurrentItem == null)
{
Logger.LogInfo("Peek: No files found to preview, showing error.");
var errorMessage = ResourceLoaderInstance.ResourceLoader.GetString("NoFilesSelected");
ViewModel.ShowError(errorMessage);

// Still show the window so user can see the warning
this.Show();
WindowHelpers.BringToForeground(this.GetWindowHandle());
return;
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

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

This change modifies the user-visible activation behavior when no item is available (e.g., caret-visible typing / no selection / virtual folders). Since Peek has an existing UI test suite (src/modules/peek/Peek.UITests), please add an automated test case that verifies Peek does not open/steal focus when Explorer is in rename mode and Space is pressed, to prevent regressions.

Copilot generated this review using guidance from repository custom instructions.
@htcfreek
Copy link
Copy Markdown
Collaborator

@niels9001
"In for 0.97" labe makes no sense. That version is released already. I think you mean "in for 0.98".

@crutkas
Copy link
Copy Markdown
Member

crutkas commented Jan 24, 2026

This could be a hotfix

@vanzue vanzue self-requested a review January 26, 2026 07:13
Copy link
Copy Markdown
Contributor

@vanzue vanzue left a comment

Choose a reason for hiding this comment

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

Wait for testing

@vanzue vanzue merged commit 0b3dc08 into main Jan 26, 2026
20 of 21 checks passed
@vanzue vanzue deleted the issue/44845 branch January 26, 2026 07:20
vanzue pushed a commit that referenced this pull request Jan 26, 2026
Don't show error window when CurrentItem is null - just return silently.
This restores the original behavior where CaretVisible() detection in
GetSelectedItems() would suppress Peek by returning null, and no window
would be shown.

PR #44703 added an error window for virtual folders (Home/Recent), but
this also triggered when user was typing (rename, search, address bar),
stealing focus and cancelling the operation.

Fixes #44845

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
@the-epoch
Copy link
Copy Markdown

Very confused - says it's been merged and closed, but v 0.97.0

@niels9001
Copy link
Copy Markdown
Collaborator

Very confused - says it's been merged and closed, but v 0.97.0

@the-epoch the fix has been merged, and with a few other fixes, will be available in 0.97.1 which we hope to roll out this week.

@samthecodingman samthecodingman mentioned this pull request Jan 28, 2026
yeelam-gordon added a commit that referenced this pull request Jan 31, 2026
Don't show error window when CurrentItem is null - just return silently.
This restores the original behavior where CaretVisible() detection in
GetSelectedItems() would suppress Peek by returning null, and no window
would be shown.

PR #44703 added an error window for virtual folders (Home/Recent), but
this also triggered when user was typing (rename, search, address bar),
stealing focus and cancelling the operation.

Fixes #44845

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
@fm-frga
Copy link
Copy Markdown

fm-frga commented Feb 6, 2026

Fixed on version 0.97.1 - no longer triggered during file rename.

@vanzue vanzue added this to the PowerToys 0.97 milestone Feb 9, 2026
@vanzue vanzue added the Product-Peek Refers to Peek Powertoys label Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.97-hotfix Product-Peek Refers to Peek Powertoys

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Peek shortcut (Space) triggers when trying to rename a file

8 participants