From fa8520e5819d882cd255628b64b3eb09ea2ccedf Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Fri, 13 Jun 2025 15:43:13 -0700 Subject: [PATCH] Manually focus panes after swapping them (#19024) (cherry picked from commit bd7e3179ff1c41e9147d99253a9ab150cf9e942a) Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgbeR18 Service-Version: 1.22 --- src/cascadia/TerminalApp/Pane.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index dc235b0602..3255c5fba3 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -697,12 +697,24 @@ bool Pane::SwapPanes(std::shared_ptr first, std::shared_ptr second) // Refocus the last pane if there was a pane focused if (const auto focus = first->GetActivePane()) { - focus->_Focus(); + // GH#18184: manually focus the pane and content. + // _Focus() results in no-op because the pane was _lastActive + focus->GotFocus.raise(focus, FocusState::Programmatic); + if (const auto& lastContent{ focus->GetLastFocusedContent() }) + { + lastContent.Focus(FocusState::Programmatic); + } } if (const auto focus = second->GetActivePane()) { - focus->_Focus(); + // GH#18184: manually focus the pane and content. + // _Focus() results in no-op because the pane was _lastActive + focus->GotFocus.raise(focus, FocusState::Programmatic); + if (const auto& lastContent{ focus->GetLastFocusedContent() }) + { + lastContent.Focus(FocusState::Programmatic); + } } return true;