Skip to content

Commit

Permalink
add single quotes to WSL drag and drop (#16214)
Browse files Browse the repository at this point in the history
Wrap single quotes to drag and dropped paths in WSL

## References and Relevant Issues
#15646  , #8109 

## Detailed Description of the Pull Request / Additional comments
First time contributor, from what I understand from reading #15646 and #8109 , issue is asking for single quotes added to a drag and dropped path always, regardless of whitespace and special characters, in WSL.

## Validation Steps Performed
Tested drag and drop changes in WSL and non WSL sources.

Closes #15646
  • Loading branch information
js324 authored Oct 24, 2023
1 parent d8c7719 commit d0d3039
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2908,7 +2908,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// However, it's likely that the control layer may need to
// know about the source anyways in the future, to support
// GH#3158
if (_interactivity.ManglePathsForWsl())
const auto isWSL = _interactivity.ManglePathsForWsl();

if (isWSL)
{
std::replace(fullPath.begin(), fullPath.end(), L'\\', L'/');

Expand Down Expand Up @@ -2942,17 +2944,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

const auto containsSpaces = std::find(fullPath.begin(),
fullPath.end(),
L' ') != fullPath.end();
const auto quotesNeeded = isWSL || fullPath.find(L' ') != std::wstring::npos;
const auto quotesChar = isWSL ? L'\'' : L'"';

if (containsSpaces)
// Append fullPath and also wrap it in quotes if needed
if (quotesNeeded)
{
fullPath.insert(0, L"\"");
fullPath += L"\"";
allPathsString.push_back(quotesChar);
}
allPathsString.append(fullPath);
if (quotesNeeded)
{
allPathsString.push_back(quotesChar);
}

allPathsString += fullPath;
}

_pasteTextWithBroadcast(winrt::hstring{ allPathsString });
Expand Down

0 comments on commit d0d3039

Please sign in to comment.