This works for #15173, but no me gusta

This commit is contained in:
Mike Griese
2023-05-01 15:00:56 -05:00
parent 072620625a
commit 3d1611f78a
2 changed files with 36 additions and 12 deletions

View File

@@ -1134,6 +1134,7 @@ namespace winrt::TerminalApp::implementation
if (dispatchToElevatedWindow)
{
newTerminalArgs.StartingDirectory(_evaluatePathForCwd(newTerminalArgs.StartingDirectory()));
_OpenElevatedWT(newTerminalArgs);
}
else
@@ -1174,6 +1175,23 @@ namespace winrt::TerminalApp::implementation
}
}
winrt::hstring TerminalPage::_evaluatePathForCwd(const winrt::hstring& path)
{
auto resultPath{ path };
const bool looksLikeLinux = resultPath.size() == 1 &&
(resultPath[0] == L'~' || resultPath[0] == L'/');
// if (newWorkingDirectory.size() == 0 || looksLikeLinux)
if (!looksLikeLinux)
{ // We only want to resolve the new WD against the CWD if it doesn't look like a Linux path (see GH#592)
// auto cwdString{ wil::GetCurrentDirectoryW<std::wstring>() };
auto cwdString{ _WindowProperties.VirtualWorkingDirectory().c_str() };
std::filesystem::path cwd{ cwdString };
cwd /= path.c_str();
resultPath = winrt::hstring{ cwd.wstring() };
}
return resultPath;
}
// Method Description:
// - Creates a new connection based on the profile settings
// Arguments:
@@ -1242,18 +1260,18 @@ namespace winrt::TerminalApp::implementation
// construction, because the connection might not spawn the child
// process until later, on another thread, after we've already
// restored the CWD to its original value.
auto newWorkingDirectory{ settings.StartingDirectory() };
const bool looksLikeLinux = newWorkingDirectory.size() == 1 &&
(newWorkingDirectory[0] == L'~' || newWorkingDirectory[0] == L'/');
// if (newWorkingDirectory.size() == 0 || looksLikeLinux)
if (!looksLikeLinux)
{ // We only want to resolve the new WD against the CWD if it doesn't look like a Linux path (see GH#592)
// auto cwdString{ wil::GetCurrentDirectoryW<std::wstring>() };
auto cwdString{ _WindowProperties.VirtualWorkingDirectory().c_str() };
std::filesystem::path cwd{ cwdString };
cwd /= settings.StartingDirectory().c_str();
newWorkingDirectory = winrt::hstring{ cwd.wstring() };
}
auto newWorkingDirectory{ _evaluatePathForCwd(settings.StartingDirectory()) };
// const bool looksLikeLinux = newWorkingDirectory.size() == 1 &&
// (newWorkingDirectory[0] == L'~' || newWorkingDirectory[0] == L'/');
// // if (newWorkingDirectory.size() == 0 || looksLikeLinux)
// if (!looksLikeLinux)
// { // We only want to resolve the new WD against the CWD if it doesn't look like a Linux path (see GH#592)
// // auto cwdString{ wil::GetCurrentDirectoryW<std::wstring>() };
// auto cwdString{ _WindowProperties.VirtualWorkingDirectory().c_str() };
// std::filesystem::path cwd{ cwdString };
// cwd /= settings.StartingDirectory().c_str();
// newWorkingDirectory = winrt::hstring{ cwd.wstring() };
// }
auto conhostConn = TerminalConnection::ConptyConnection();
auto valueSet = TerminalConnection::ConptyConnection::CreateSettings(settings.Commandline(),
@@ -4273,6 +4291,9 @@ namespace winrt::TerminalApp::implementation
// whatever the default profile's GUID is.
newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid()));
newTerminalArgs.StartingDirectory(_evaluatePathForCwd(controlSettings.DefaultSettings().StartingDirectory()));
_OpenElevatedWT(newTerminalArgs);
return true;
}

View File

@@ -295,6 +295,9 @@ namespace winrt::TerminalApp::implementation
void _OpenNewTabDropdown();
HRESULT _OpenNewTab(const Microsoft::Terminal::Settings::Model::NewTerminalArgs& newTerminalArgs, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr);
void _CreateNewTabFromPane(std::shared_ptr<Pane> pane, uint32_t insertPosition = -1);
winrt::hstring _evaluatePathForCwd(const winrt::hstring& path);
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _CreateConnectionFromSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettings settings, const bool inheritCursor);
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _duplicateConnectionForRestart(std::shared_ptr<Pane> pane);
void _restartPaneConnection(const std::shared_ptr<Pane>& pane);