control: focus terminal on click-drag while search is open#19931
Merged
carlos-zamora merged 1 commit intomicrosoft:mainfrom Mar 11, 2026
Merged
control: focus terminal on click-drag while search is open#19931carlos-zamora merged 1 commit intomicrosoft:mainfrom
carlos-zamora merged 1 commit intomicrosoft:mainfrom
Conversation
When the search dialog is open and the user click-drags in the terminal to select text, the TermControl doesn't receive keyboard focus because `_focused` is already true (set via the bubbling GotFocus from the search box child element). This means `Focus(FocusState::Pointer)` is skipped, keyboard focus stays on the search box's TextBox, and Ctrl+C copies from the TextBox rather than copying the selected terminal text. Fix this by also calling Focus() when the search box contains focus, which is consistent with _TappedHandler (which focuses unconditionally) and with how ContainsFocus() is already used elsewhere in the file. Closes microsoft#19908
carlos-zamora
approved these changes
Mar 11, 2026
Member
carlos-zamora
left a comment
There was a problem hiding this comment.
Perfect! Love how small the fix is. Thanks for doing this!
Member
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
DHowett
pushed a commit
that referenced
this pull request
Mar 12, 2026
## Summary - Fix inability to copy terminal text via Ctrl+C when the search dialog is open - Root cause: click-and-drag doesn't call `Focus()` because `_focused` is already `true` (set by the search box's bubbling GotFocus) - Fix: also focus the terminal when the search box contains keyboard focus ## Detailed Description of the Pull Request / Additional comments When the search dialog is open and the user click-drags in the terminal to select text, `_PointerPressedHandler` skips `Focus(FocusState::Pointer)` because `_focused` is `true`. The `_focused` flag is `true` because the `SearchBoxControl` is a child of `TermControl` in the XAML visual tree, so `TermControl`'s `_GotFocusHandler` fires (via bubbling `GotFocus`) when the search box's `TextBox` gains focus, setting `_focused = true`. The fix adds a `ContainsFocus()` check so that focus is explicitly moved to the terminal when the search box has keyboard focus. This makes click-drag behavior consistent with tap behavior (`_TappedHandler` already focuses unconditionally) and uses the same `ContainsFocus()` pattern already established at lines 1569 and 2366 in the same file. ## Validation Steps Performed - Verified click-drag + Ctrl+C copies selected text when search dialog is open - Verified simple click (tap) in terminal while search is open still works - Verified clicking in the search box retains focus in the search box - Verified typing in search box still works when it has focus - Verified Escape still closes the search box - Verified Ctrl+C with no selection while search is open doesn't break - Code formatted with clang-format ## PR Checklist Closes #19908 (cherry picked from commit e2d5163) Service-Card-Id: PVTI_lADOAF3p4s4BBcTlzgnN_t0 Service-Version: 1.24
DHowett
pushed a commit
that referenced
this pull request
Mar 12, 2026
## Summary - Fix inability to copy terminal text via Ctrl+C when the search dialog is open - Root cause: click-and-drag doesn't call `Focus()` because `_focused` is already `true` (set by the search box's bubbling GotFocus) - Fix: also focus the terminal when the search box contains keyboard focus ## Detailed Description of the Pull Request / Additional comments When the search dialog is open and the user click-drags in the terminal to select text, `_PointerPressedHandler` skips `Focus(FocusState::Pointer)` because `_focused` is `true`. The `_focused` flag is `true` because the `SearchBoxControl` is a child of `TermControl` in the XAML visual tree, so `TermControl`'s `_GotFocusHandler` fires (via bubbling `GotFocus`) when the search box's `TextBox` gains focus, setting `_focused = true`. The fix adds a `ContainsFocus()` check so that focus is explicitly moved to the terminal when the search box has keyboard focus. This makes click-drag behavior consistent with tap behavior (`_TappedHandler` already focuses unconditionally) and uses the same `ContainsFocus()` pattern already established at lines 1569 and 2366 in the same file. ## Validation Steps Performed - Verified click-drag + Ctrl+C copies selected text when search dialog is open - Verified simple click (tap) in terminal while search is open still works - Verified clicking in the search box retains focus in the search box - Verified typing in search box still works when it has focus - Verified Escape still closes the search box - Verified Ctrl+C with no selection while search is open doesn't break - Code formatted with clang-format ## PR Checklist Closes #19908 (cherry picked from commit e2d5163) Service-Card-Id: PVTI_lADOAF3p4s4BQX0-zgnOgZ8 Service-Version: 1.25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Focus()because_focusedis alreadytrue(set by the search box's bubbling GotFocus)Detailed Description of the Pull Request / Additional comments
When the search dialog is open and the user click-drags in the terminal to select text,
_PointerPressedHandlerskipsFocus(FocusState::Pointer)because_focusedistrue. The_focusedflag istruebecause theSearchBoxControlis a child ofTermControlin the XAML visual tree, soTermControl's_GotFocusHandlerfires (via bubblingGotFocus) when the search box'sTextBoxgains focus, setting_focused = true.The fix adds a
ContainsFocus()check so that focus is explicitly moved to the terminal when the search box has keyboard focus. This makes click-drag behavior consistent with tap behavior (_TappedHandleralready focuses unconditionally) and uses the sameContainsFocus()pattern already established at lines 1569 and 2366 in the same file.Validation Steps Performed
PR Checklist
Closes #19908