GREAT-GRANDPARENT: This fixes a crash in parent pane selection

(cherry picked from commit 91a0d0e26d)
This commit is contained in:
Mike Griese
2024-03-07 09:49:48 -06:00
parent 4d47cd5866
commit b6254f8294
3 changed files with 34 additions and 3 deletions

View File

@@ -1106,6 +1106,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;
@@ -1246,7 +1269,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:
@@ -1925,7 +1952,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

View File

@@ -73,6 +73,7 @@ public:
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;

View File

@@ -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();
}
}
}