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 drag and drop on '+' button for drive letters #10842

Merged
2 commits merged into from
Aug 3, 2021
Merged
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
21 changes: 20 additions & 1 deletion src/cascadia/LocalTests_SettingsModel/CommandTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ namespace SettingsModelLocalTests
"name":"action6",
"command": { "action": "newWindow", "startingDirectory":"C:\\foo", "commandline": "bar.exe" }
},
{
"name":"action7_startingDirectoryWithTrailingSlash",
"command": { "action": "newWindow", "startingDirectory":"C:\\", "commandline": "bar.exe" }
},
])" };

const auto commands0Json = VerifyParseSucceeded(commands0String);
Expand All @@ -405,7 +409,7 @@ namespace SettingsModelLocalTests
VERIFY_ARE_EQUAL(0u, commands.Size());
auto warnings = implementation::Command::LayerJson(commands, commands0Json);
VERIFY_ARE_EQUAL(0u, warnings.size());
VERIFY_ARE_EQUAL(7u, commands.Size());
VERIFY_ARE_EQUAL(8u, commands.Size());

{
auto command = commands.Lookup(L"action0");
Expand Down Expand Up @@ -503,5 +507,20 @@ namespace SettingsModelLocalTests
L"cmdline: \"%s\"", cmdline.c_str()));
VERIFY_ARE_EQUAL(L"--startingDirectory \"C:\\foo\" -- \"bar.exe\"", terminalArgs.ToCommandline());
}

{
auto command = commands.Lookup(L"action7_startingDirectoryWithTrailingSlash");
VERIFY_IS_NOT_NULL(command);
VERIFY_IS_NOT_NULL(command.ActionAndArgs());
VERIFY_ARE_EQUAL(ShortcutAction::NewWindow, command.ActionAndArgs().Action());
const auto& realArgs = command.ActionAndArgs().Args().try_as<NewWindowArgs>();
VERIFY_IS_NOT_NULL(realArgs);
const auto& terminalArgs = realArgs.TerminalArgs();
VERIFY_IS_NOT_NULL(terminalArgs);
auto cmdline = terminalArgs.ToCommandline();
Log::Comment(NoThrowString().Format(
L"cmdline: \"%s\"", cmdline.c_str()));
VERIFY_ARE_EQUAL(L"--startingDirectory \"C:\\\\\" -- \"bar.exe\"", terminalArgs.ToCommandline());
}
}
}
10 changes: 1 addition & 9 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,8 @@ namespace winrt::TerminalApp::implementation
path = path.parent_path();
}

std::wstring pathText = path.wstring();

// Handle edge case of "C:\\", seems like the "StartingDirectory" doesn't like path which ends with '\'
Copy link
Member

Choose a reason for hiding this comment

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

I'm actually quite surprised by this premise. The reason we have issues with StartingDirectory when passed through the commandline are ones of escaping.

Does it really beef it if we don't do this trick at all? huh.

Copy link
Member

@DHowett DHowett Aug 2, 2021

Choose a reason for hiding this comment

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

(because the commandline escaping for wt results in "C:\" being parsed as C:\" (terminating quote captured in path))

Copy link
Member

Choose a reason for hiding this comment

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

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - this is purely for the "Open in new window" case

If I comment out the pathText.push_back(L'.') and drop on C:\ with shift pressed, the new window fails to parse the command line:

image

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drag and dropping C:\ to get a new tab or split the current window works fine, it's just the new window case that fails.

Copy link
Member

Choose a reason for hiding this comment

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

OH. Okay.

We should fix this in the New Window commandline generator, honestly. That would also fix it for shift-clicking the cmd2 profile I created to test this. 😄

I suspect that this code lives in NewTerminalArgs::ToCommandline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - with the added bonus that this now has a test 🙂

Copy link
Member

Choose a reason for hiding this comment

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

Love it! Thank you!

if (pathText.back() == L'\\')
{
pathText.erase(std::prev(pathText.end()));
}

NewTerminalArgs args;
args.StartingDirectory(winrt::hstring{ pathText });
args.StartingDirectory(winrt::hstring{ path.wstring() });
this->_OpenNewTerminal(args);

TraceLoggingWrite(
Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/TerminalSettingsModel/ActionArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

if (!StartingDirectory().empty())
{
ss << fmt::format(L"--startingDirectory \"{}\" ", StartingDirectory());
// If the directory ends in a '\', we need to add another one on so that the enclosing quote added
// afterwards isn't escaped
const auto trailingBackslashEscape = StartingDirectory().back() == L'\\' ? L"\\" : L"";
ss << fmt::format(L"--startingDirectory \"{}{}\" ", StartingDirectory(), trailingBackslashEscape);
}

if (!TabTitle().empty())
Expand Down