Skip to content

Enable Copy As Path/Paste with Path Translation in *nix profiles #19037

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jamespack
Copy link
Contributor

Summary of the Pull Request

Copy as Path / Paste with PathTranslation for *nix profiles in Terminal.

References and Relevant Issues

#18544

Detailed Description of the Pull Request / Additional comments

Path translation for drag and drop is already a thing. This pull request takes it one step further and enables Copy As Path on a file/directory and then pasting in terminal. If the profile has a PathTranslationStyle configured the path will be translated before paste.

Validation Steps Performed

This was validated to work on my machine.

PR Checklist

@@ -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.

@@ -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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants