Skip to content
Open
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
20 changes: 20 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "../../renderer/uia/UiaRenderer.hpp"
#include "../../types/inc/CodepointWidthDetector.hpp"

#include "TermControl.h"

#include "ControlCore.g.cpp"
#include "SelectionColor.g.cpp"

Expand Down Expand Up @@ -1441,6 +1443,24 @@ namespace winrt::Microsoft::Terminal::Control::implementation
using namespace ::Microsoft::Console::Utils;

auto filtered = FilterStringForPaste(hstr, CarriageReturnNewline | ControlCodes);
std::filesystem::path path{ filtered };
Copy link
Member

Choose a reason for hiding this comment

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

Why wrap it in a path first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I didn't want to blindly send all text to the translation routine. If we don't have a path, it doesnt make sense to even try to translate it.

Copy link
Member

Choose a reason for hiding this comment

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

If I'm reading your code correctly, if you replace all mentions of the path variable with filtered, the code will do the exact same it does now. But it would avoid making a redundant copy of the string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can remove the path piece

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the translation routine does do some checks that it is looking at a path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was being over cautious I suppose.


if (!path.empty() && _settings->PathTranslationStyle() != PathTranslationStyle::None)
{
filtered = path.wstring();
// Explorer puts paths wrapped in double quotes on the clipboard. The translation routine expects it to be without quotes.
if (!filtered.empty() && filtered.front() == '\"')
{
filtered.erase(0, 1);
}
if (!filtered.empty() && filtered.back() == '\"')
{
filtered.pop_back();
}

TermControl::_translatePathInPlace(filtered, _settings->PathTranslationStyle());
}

if (BracketedPasteEnabled())
{
filtered.insert(0, L"\x1b[200~");
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

friend class ControlUnitTests::ControlCoreTests;
friend class ControlUnitTests::ControlInteractivityTests;

bool _inUnitTests{ false };
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static Microsoft::Console::TSF::Handle& GetTSFHandle()

namespace winrt::Microsoft::Terminal::Control::implementation
{
static void _translatePathInPlace(std::wstring& fullPath, PathTranslationStyle translationStyle)
void TermControl::_translatePathInPlace(std::wstring& fullPath, PathTranslationStyle translationStyle)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you want me to move this or is what I did here ok?

{
static constexpr wil::zwstring_view s_pathPrefixes[] = {
{},
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
uint64_t ContentId() const;

hstring GetProfileName() const;
static void _translatePathInPlace(std::wstring& fullPath, PathTranslationStyle translationStyle);

bool CopySelectionToClipboard(bool dismissSelection, bool singleLine, bool withControlSequences, const Windows::Foundation::IReference<CopyFormat>& formats);
void PasteTextFromClipboard();
Expand Down
Loading