Skip to content

Fix: Prevent Enter key leaking to terminal during Command Palette actions#20221

Closed
nicolasalarconrapela wants to merge 1 commit into
microsoft:mainfrom
nicolasalarconrapela:fix/command-palette-enter-leak
Closed

Fix: Prevent Enter key leaking to terminal during Command Palette actions#20221
nicolasalarconrapela wants to merge 1 commit into
microsoft:mainfrom
nicolasalarconrapela:fix/command-palette-enter-leak

Conversation

@nicolasalarconrapela

@nicolasalarconrapela nicolasalarconrapela commented May 13, 2026

Copy link
Copy Markdown

Summary of the Pull Request

This PR addresses the issue reported in #20188, where triggering the "Export Text" action from the Command Palette would result in a phantom Enter key press being sent to the active terminal session.

The original implementation marked the event as handled (args.Handled(true)) only after invoking the _ExportTab function. When no predefined file path is provided (the default behavior in the Command Palette), _ExportTab triggers a modal Windows dialog (FileSavePicker). This system dialog captures the UI focus immediately.

The Problem

Because the focus shifted before the event was marked as handled, the WinUI event routing system allowed the residual Enter keystroke to "leak" into the terminal control that regained focus in the background.

This behavior might stem from an early design focus on single-window control architectures, as seen in previous discussions like: #6635

Solution

  1. Early Neutralization: Moved args.Handled(true); to the very beginning of the _HandleExportBuffer method. This ensures the Enter event is consumed by the Command Palette while it still holds focus, preventing any further propagation.

  2. Flow Refactoring: Refactored the method to utilize a single execution path for _ExportTab. The method now prepares the path string and executes the call once, improving code readability and ensuring consistent behavior regardless of whether a path argument is provided.

Validation Steps Performed

Before

before

After

after

PR Checklist

@nicolasalarconrapela

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@nicolasalarconrapela nicolasalarconrapela marked this pull request as ready for review May 14, 2026 10:32
@nicolasalarconrapela nicolasalarconrapela changed the title Fix: Prevent Enter key leaking to terminal during Command Palette actions (#20188) Fix: Prevent Enter key leaking to terminal during Command Palette actions May 15, 2026

@carlos-zamora carlos-zamora left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution! Sorry for the delay in reviewing this.

I've verified that this does fix the issue. However, I think this change can be simplified a bit. Rather than detecting if it's an export buffer action in the command palette, we can add co_await wil::resume_foreground(Dispatcher()); to _ExportTab() directly. I'm going ahead and opening a separate PR for this. Thanks again for looking into this!

@carlos-zamora

Copy link
Copy Markdown
Member

Closing in favor of #20358

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Export text" action invoked from cmd paletter forwards Enter key

2 participants