Skip to content

control: focus terminal on click-drag while search is open#19931

Merged
carlos-zamora merged 1 commit intomicrosoft:mainfrom
4RH1T3CT0R7:fix/19908-copy-with-search-open
Mar 11, 2026
Merged

control: focus terminal on click-drag while search is open#19931
carlos-zamora merged 1 commit intomicrosoft:mainfrom
4RH1T3CT0R7:fix/19908-copy-with-search-open

Conversation

@4RH1T3CT0R7
Copy link
Copy Markdown
Contributor

@4RH1T3CT0R7 4RH1T3CT0R7 commented Mar 3, 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

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
Copy link
Copy Markdown
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

Perfect! Love how small the fix is. Thanks for doing this!

@carlos-zamora
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@carlos-zamora carlos-zamora enabled auto-merge (squash) March 11, 2026 17:29
@github-project-automation github-project-automation bot moved this to To Cherry Pick in 1.23 Servicing Pipeline Mar 11, 2026
@github-project-automation github-project-automation bot moved this to To Cherry Pick in 1.24 Servicing Pipeline Mar 11, 2026
@carlos-zamora carlos-zamora merged commit e2d5163 into microsoft:main Mar 11, 2026
14 of 16 checks passed
@github-project-automation github-project-automation bot moved this to To Cherry Pick in 1.25 Servicing Pipeline Mar 11, 2026
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.24 Servicing Pipeline Mar 12, 2026
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 DHowett moved this from To Cherry Pick to Cherry Picked in 1.25 Servicing Pipeline Mar 12, 2026
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
@DHowett DHowett moved this from Cherry Picked to Shipped in 1.25 Servicing Pipeline Mar 31, 2026
@DHowett DHowett moved this from Shipped to Cherry Picked in 1.25 Servicing Pipeline Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Cherry Picked
Status: Cherry Picked

Development

Successfully merging this pull request may close these issues.

Unable to copy text when search dialog box is open

3 participants