Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid async infinite loop on tab close #15335

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/cascadia/TerminalApp/TabBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace winrt::TerminalApp::implementation
ASSERT_UI_THREAD();

Content(nullptr);
_ClosedHandlers(nullptr, nullptr);
}

// Method Description:
Expand Down
14 changes: 11 additions & 3 deletions src/cascadia/TerminalApp/TabManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,13 @@ namespace winrt::TerminalApp::implementation
});

// When the tab is closed, remove it from our list of tabs.
newTabImpl->Closed([tabViewItem, weakThis{ get_weak() }](auto&& /*s*/, auto&& /*e*/) {
if (auto page{ weakThis.get() })
newTabImpl->Closed([weakTab, weakThis{ get_weak() }](auto&& /*s*/, auto&& /*e*/) {
const auto page = weakThis.get();
const auto tab = weakTab.get();

if (page && tab)
{
page->_RemoveOnCloseRoutine(tabViewItem, page);
page->_RemoveTab(*tab);
}
});

Expand Down Expand Up @@ -509,6 +512,11 @@ namespace winrt::TerminalApp::implementation
_mruTabs.RemoveAt(mruIndex);
}

if (tab == _settingsTab)
{
_settingsTab = nullptr;
}
Comment on lines +527 to +530
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt like this is a more robust way to express the same idea of "there's just one instance of settings and closing it destroys it".


if (_stashed.draggedTab && *_stashed.draggedTab == tab)
{
_stashed.draggedTab = nullptr;
Expand Down
20 changes: 6 additions & 14 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,16 +1148,6 @@ namespace winrt::TerminalApp::implementation
}
}

winrt::fire_and_forget TerminalPage::_RemoveOnCloseRoutine(Microsoft::UI::Xaml::Controls::TabViewItem tabViewItem, winrt::com_ptr<TerminalPage> page)
{
co_await wil::resume_foreground(page->_tabView.Dispatcher());

if (auto tab{ _GetTabByTabViewItem(tabViewItem) })
{
_RemoveTab(tab);
}
}

// Method Description:
// - Creates a new connection based on the profile settings
// Arguments:
Expand Down Expand Up @@ -3752,11 +3742,13 @@ namespace winrt::TerminalApp::implementation
});

// When the tab is closed, remove it from our list of tabs.
newTabImpl->Closed([tabViewItem, weakThis{ get_weak() }](auto&& /*s*/, auto&& /*e*/) {
if (auto page{ weakThis.get() })
newTabImpl->Closed([weakTab, weakThis{ get_weak() }](auto&& /*s*/, auto&& /*e*/) {
const auto page = weakThis.get();
const auto tab = weakTab.get();

if (page && tab)
{
page->_settingsTab = nullptr;
page->_RemoveOnCloseRoutine(tabViewItem, page);
page->_RemoveTab(*tab);
}
});

Expand Down
2 changes: 0 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,6 @@ namespace winrt::TerminalApp::implementation
winrt::Windows::Foundation::IAsyncOperation<bool> _PaneConfirmCloseReadOnly(std::shared_ptr<Pane> pane);
void _AddPreviouslyClosedPaneOrTab(std::vector<Microsoft::Terminal::Settings::Model::ActionAndArgs>&& args);

winrt::fire_and_forget _RemoveOnCloseRoutine(Microsoft::UI::Xaml::Controls::TabViewItem tabViewItem, winrt::com_ptr<TerminalPage> page);

void _Scroll(ScrollDirection scrollDirection, const Windows::Foundation::IReference<uint32_t>& rowsToScroll);

void _SplitPane(const Microsoft::Terminal::Settings::Model::SplitDirection splitType,
Expand Down