Skip to content

Commit

Permalink
GREAT-GRANDPARENT: This fixes a crash in parent pane selection
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Mar 7, 2024
1 parent 18bd6a8 commit 91a0d0e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
31 changes: 29 additions & 2 deletions src/cascadia/TerminalApp/Pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,29 @@ TermControl Pane::GetLastFocusedTerminalControl()
}
}

IPaneContent Pane::GetLastFocusedContent()
{
if (!_IsLeaf())
{
if (_lastActive)
{
auto pane = shared_from_this();
while (const auto p = pane->_parentChildPath.lock())
{
if (p->_IsLeaf())
{
return p->_content;
}
pane = p;
}
// We didn't find our child somehow, they might have closed under us.
}
return _firstChild->GetLastFocusedContent();
}

return _content;
}

// Method Description:
// - Gets the TermControl of this pane. If this Pane is not a leaf this will
// return the nullptr;
Expand Down Expand Up @@ -1480,7 +1503,11 @@ void Pane::UpdateVisuals()
void Pane::_Focus()
{
_GotFocusHandlers(shared_from_this(), FocusState::Programmatic);
_content.Focus(FocusState::Programmatic);
if (const auto& lastContent{ GetLastFocusedContent() })
{
lastContent.Focus(FocusState::Programmatic);
}

}

// Method Description:
Expand Down Expand Up @@ -2176,7 +2203,7 @@ void Pane::_SetupEntranceAnimation()
auto child = isFirstChild ? _firstChild : _secondChild;
auto childGrid = child->_root;
// If we are splitting a parent pane this may be null
auto control = child->_content.GetRoot();
auto control = child->_content ? child->_content.GetRoot() : nullptr;
// Build up our animation:
// * it'll take as long as our duration (200ms)
// * it'll change the value of our property from 0 to secondSize
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/Pane.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Pane : public std::enable_shared_from_this<Pane>

std::shared_ptr<Pane> GetActivePane();
winrt::Microsoft::Terminal::Control::TermControl GetLastFocusedTerminalControl();
winrt::TerminalApp::IPaneContent GetLastFocusedContent();
winrt::Microsoft::Terminal::Control::TermControl GetTerminalControl() const;
winrt::Microsoft::Terminal::Settings::Model::Profile GetFocusedProfile();
bool IsConnectionClosed() const;
Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4598,7 +4598,10 @@ namespace winrt::TerminalApp::implementation
{
if (const auto& pane{ tab->GetActivePane() })
{
terminalBrush = pane->GetContent().BackgroundBrush();
if (const auto& lastContent{ pane->GetLastFocusedContent() })
{
terminalBrush = lastContent.BackgroundBrush();
}
}
}

Expand Down

0 comments on commit 91a0d0e

Please sign in to comment.