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

Fix issue #17237 #18490

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 11 additions & 5 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,7 @@ namespace winrt::TerminalApp::implementation
return connection;
}

// use _replaceConnectionForRestart instead of using this function directly. _replaceConnectionForRestart will close the old connection.
TerminalConnection::ITerminalConnection TerminalPage::_duplicateConnectionForRestart(const TerminalApp::TerminalPaneContent& paneContent)
Comment on lines +1365 to 1366
Copy link
Member

Choose a reason for hiding this comment

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

Hmm... If we shouldn't use _duplicateConnectionForRestart and there's only one place we're using it (in _replaceConnectionForRestart), can we just combine them so nobody uses the wrong one in the future?

{
if (paneContent == nullptr)
Expand Down Expand Up @@ -1405,6 +1406,15 @@ namespace winrt::TerminalApp::implementation
return _CreateConnectionFromSettings(profile, controlSettings.DefaultSettings(), true);
}

void TerminalPage::_replaceConnectionForRestart(const TerminalApp::TerminalPaneContent& paneContent) {
if (const auto& connection{ _duplicateConnectionForRestart(paneContent) }) {
auto previousConnection = paneContent.GetTermControl().Connection();
paneContent.GetTermControl().Connection(connection);
connection.Start();
previousConnection.Close();
}
}

// Method Description:
// - Called when the settings button is clicked. Launches a background
// thread to open the settings file in the default JSON editor.
Expand Down Expand Up @@ -3471,11 +3481,7 @@ namespace winrt::TerminalApp::implementation
// the TermControl.RestartTerminalRequested event doesn't actually pass
// any args upwards itself. If we ever change this, make sure you check
// for nulls
if (const auto& connection{ _duplicateConnectionForRestart(paneContent) })
{
paneContent.GetTermControl().Connection(connection);
connection.Start();
}
_replaceConnectionForRestart(paneContent);
}

// Method Description:
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ namespace winrt::TerminalApp::implementation
std::wstring _evaluatePathForCwd(std::wstring_view path);

winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _CreateConnectionFromSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettings settings, const bool inheritCursor);
void _replaceConnectionForRestart(const TerminalApp::TerminalPaneContent& paneContent);
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _duplicateConnectionForRestart(const TerminalApp::TerminalPaneContent& paneContent);
void _restartPaneConnection(const TerminalApp::TerminalPaneContent&, const winrt::Windows::Foundation::IInspectable&);

Expand Down
Loading