@@ -41,7 +41,7 @@ namespace winrt::TerminalApp::implementation
41
41
42
42
auto firstId = _nextPaneId;
43
43
44
- _rootPane->WalkTree ([&](std::shared_ptr<Pane> pane) {
44
+ _rootPane->WalkTree ([&](const auto & pane) {
45
45
// update the IDs on each pane
46
46
if (pane->_IsLeaf ())
47
47
{
@@ -203,7 +203,7 @@ namespace winrt::TerminalApp::implementation
203
203
{
204
204
ASSERT_UI_THREAD ();
205
205
206
- _rootPane->WalkTree ([&](std::shared_ptr<Pane> pane) {
206
+ _rootPane->WalkTree ([&](const auto & pane) {
207
207
// Attach event handlers to each new pane
208
208
_AttachEventHandlersToPane (pane);
209
209
if (auto content = pane->GetContent ())
@@ -275,7 +275,7 @@ namespace winrt::TerminalApp::implementation
275
275
_UpdateHeaderControlMaxWidth ();
276
276
277
277
// Update the settings on all our panes.
278
- _rootPane->WalkTree ([&](auto pane) {
278
+ _rootPane->WalkTree ([&](const auto & pane) {
279
279
pane->UpdateSettings (settings);
280
280
return false ;
281
281
});
@@ -534,7 +534,7 @@ namespace winrt::TerminalApp::implementation
534
534
535
535
// Add the new event handlers to the new pane(s)
536
536
// and update their ids.
537
- pane->WalkTree ([&](auto p) {
537
+ pane->WalkTree ([&](const auto & p) {
538
538
_AttachEventHandlersToPane (p);
539
539
if (p->_IsLeaf ())
540
540
{
@@ -624,7 +624,7 @@ namespace winrt::TerminalApp::implementation
624
624
// manually.
625
625
_rootPane->Closed (_rootClosedToken);
626
626
auto p = _rootPane;
627
- p->WalkTree ([](auto pane) {
627
+ p->WalkTree ([](const auto & pane) {
628
628
pane->Detached .raise (pane);
629
629
});
630
630
@@ -650,7 +650,7 @@ namespace winrt::TerminalApp::implementation
650
650
651
651
// Add the new event handlers to the new pane(s)
652
652
// and update their ids.
653
- pane->WalkTree ([&](auto p) {
653
+ pane->WalkTree ([&](const auto & p) {
654
654
_AttachEventHandlersToPane (p);
655
655
if (p->_IsLeaf ())
656
656
{
@@ -949,26 +949,20 @@ namespace winrt::TerminalApp::implementation
949
949
950
950
events.CloseRequested = content.CloseRequested (
951
951
winrt::auto_revoke,
952
- [dispatcher, weakThis](auto sender, auto &&) -> winrt::fire_and_forget {
953
- // Don't forget! this ^^^^^^^^ sender can't be a reference, this is a async callback.
954
-
955
- // The lambda lives in the `std::function`-style container owned by `control`. That is, when the
956
- // `control` gets destroyed the lambda struct also gets destroyed. In other words, we need to
957
- // copy `weakThis` onto the stack, because that's the only thing that gets captured in coroutines.
958
- // See: https://devblogs.microsoft.com/oldnewthing/20211103-00/?p=105870
959
- const auto weakThisCopy = weakThis;
960
- co_await wil::resume_foreground (dispatcher);
961
- // Check if Tab's lifetime has expired
962
- if (auto tab{ weakThisCopy.get () })
952
+ [this ](auto && sender, auto &&) {
953
+ if (const auto content{ sender.try_as <TerminalApp::IPaneContent>() })
963
954
{
964
- if (const auto content{ sender.try_as <TerminalApp::IPaneContent>() })
955
+ // Calling Close() while walking the tree is not safe, because Close() mutates the tree.
956
+ const auto pane = _rootPane->_FindPane ([&](const auto & p) -> std::shared_ptr<Pane> {
957
+ if (p->GetContent () == content)
958
+ {
959
+ return p;
960
+ }
961
+ return {};
962
+ });
963
+ if (pane)
965
964
{
966
- tab->_rootPane ->WalkTree ([content](std::shared_ptr<Pane> pane) {
967
- if (pane->GetContent () == content)
968
- {
969
- pane->Close ();
970
- }
971
- });
965
+ pane->Close ();
972
966
}
973
967
}
974
968
});
0 commit comments