Skip to content

Commit b6254f8

Browse files
committed
GREAT-GRANDPARENT: This fixes a crash in parent pane selection
(cherry picked from commit 91a0d0e)
1 parent 4d47cd5 commit b6254f8

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/cascadia/TerminalApp/Pane.cpp

+29-2
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,29 @@ TermControl Pane::GetLastFocusedTerminalControl()
11061106
}
11071107
}
11081108

1109+
IPaneContent Pane::GetLastFocusedContent()
1110+
{
1111+
if (!_IsLeaf())
1112+
{
1113+
if (_lastActive)
1114+
{
1115+
auto pane = shared_from_this();
1116+
while (const auto p = pane->_parentChildPath.lock())
1117+
{
1118+
if (p->_IsLeaf())
1119+
{
1120+
return p->_content;
1121+
}
1122+
pane = p;
1123+
}
1124+
// We didn't find our child somehow, they might have closed under us.
1125+
}
1126+
return _firstChild->GetLastFocusedContent();
1127+
}
1128+
1129+
return _content;
1130+
}
1131+
11091132
// Method Description:
11101133
// - Gets the TermControl of this pane. If this Pane is not a leaf this will
11111134
// return the nullptr;
@@ -1246,7 +1269,11 @@ void Pane::UpdateVisuals()
12461269
void Pane::_Focus()
12471270
{
12481271
_GotFocusHandlers(shared_from_this(), FocusState::Programmatic);
1249-
_content.Focus(FocusState::Programmatic);
1272+
if (const auto& lastContent{ GetLastFocusedContent() })
1273+
{
1274+
lastContent.Focus(FocusState::Programmatic);
1275+
}
1276+
12501277
}
12511278

12521279
// Method Description:
@@ -1925,7 +1952,7 @@ void Pane::_SetupEntranceAnimation()
19251952
auto child = isFirstChild ? _firstChild : _secondChild;
19261953
auto childGrid = child->_root;
19271954
// If we are splitting a parent pane this may be null
1928-
auto control = child->_content.GetRoot();
1955+
auto control = child->_content ? child->_content.GetRoot() : nullptr;
19291956
// Build up our animation:
19301957
// * it'll take as long as our duration (200ms)
19311958
// * it'll change the value of our property from 0 to secondSize

src/cascadia/TerminalApp/Pane.h

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Pane : public std::enable_shared_from_this<Pane>
7373

7474
std::shared_ptr<Pane> GetActivePane();
7575
winrt::Microsoft::Terminal::Control::TermControl GetLastFocusedTerminalControl();
76+
winrt::TerminalApp::IPaneContent GetLastFocusedContent();
7677
winrt::Microsoft::Terminal::Control::TermControl GetTerminalControl() const;
7778
winrt::Microsoft::Terminal::Settings::Model::Profile GetFocusedProfile();
7879
bool IsConnectionClosed() const;

src/cascadia/TerminalApp/TerminalPage.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -4598,7 +4598,10 @@ namespace winrt::TerminalApp::implementation
45984598
{
45994599
if (const auto& pane{ tab->GetActivePane() })
46004600
{
4601-
terminalBrush = pane->GetContent().BackgroundBrush();
4601+
if (const auto& lastContent{ pane->GetLastFocusedContent() })
4602+
{
4603+
terminalBrush = lastContent.BackgroundBrush();
4604+
}
46024605
}
46034606
}
46044607

0 commit comments

Comments
 (0)