Skip to content

Commit 91a0d0e

Browse files
committed
GREAT-GRANDPARENT: This fixes a crash in parent pane selection
1 parent 18bd6a8 commit 91a0d0e

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
@@ -1340,6 +1340,29 @@ TermControl Pane::GetLastFocusedTerminalControl()
13401340
}
13411341
}
13421342

1343+
IPaneContent Pane::GetLastFocusedContent()
1344+
{
1345+
if (!_IsLeaf())
1346+
{
1347+
if (_lastActive)
1348+
{
1349+
auto pane = shared_from_this();
1350+
while (const auto p = pane->_parentChildPath.lock())
1351+
{
1352+
if (p->_IsLeaf())
1353+
{
1354+
return p->_content;
1355+
}
1356+
pane = p;
1357+
}
1358+
// We didn't find our child somehow, they might have closed under us.
1359+
}
1360+
return _firstChild->GetLastFocusedContent();
1361+
}
1362+
1363+
return _content;
1364+
}
1365+
13431366
// Method Description:
13441367
// - Gets the TermControl of this pane. If this Pane is not a leaf this will
13451368
// return the nullptr;
@@ -1480,7 +1503,11 @@ void Pane::UpdateVisuals()
14801503
void Pane::_Focus()
14811504
{
14821505
_GotFocusHandlers(shared_from_this(), FocusState::Programmatic);
1483-
_content.Focus(FocusState::Programmatic);
1506+
if (const auto& lastContent{ GetLastFocusedContent() })
1507+
{
1508+
lastContent.Focus(FocusState::Programmatic);
1509+
}
1510+
14841511
}
14851512

14861513
// Method Description:
@@ -2176,7 +2203,7 @@ void Pane::_SetupEntranceAnimation()
21762203
auto child = isFirstChild ? _firstChild : _secondChild;
21772204
auto childGrid = child->_root;
21782205
// If we are splitting a parent pane this may be null
2179-
auto control = child->_content.GetRoot();
2206+
auto control = child->_content ? child->_content.GetRoot() : nullptr;
21802207
// Build up our animation:
21812208
// * it'll take as long as our duration (200ms)
21822209
// * 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)