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

Don't copy before pasting in copyOnSelect mode #14635

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

Conversation

zadjii-msft
Copy link
Member

Don't try to copy if we're in copyOnSelect mode, and have already copied this selection.

#14464 demonstrates a scenario where the buffer contents might have changed since the selection was made, and copying here would cause weirdness.

Also adds a couple tests for copyOnSelect.

Closes #14464

@ghost ghost added Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. labels Jan 5, 2023
@github-actions

This comment has been minimized.

@KalleOlaviNiemitalo
Copy link

This changes only the handling of mouse right-clicks, right?

I have copy-on-select enabled. Occasionally, I select some text in the terminal and paste it to another program; then copy some other text from a third program and paste that too; then want to paste the text from the terminal again. In that situation, I have been able to switch back to the terminal, where the original text remains selected, and press Ctrl+Insert to copy the same text again.

Now, this PR apparently prevents copying with the right mouse button in that scenario -- well, that's okay but please don't hurt my precious Ctrl+Insert.

@zadjii-msft zadjii-msft added this to the Terminal v1.17 milestone Jan 10, 2023
Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

Bug:

  1. ensure copy on select is enabled
  2. enter mark mode
  3. make a selection with mark mode
  4. right-click to copy/paste

expected: selection is copied and pasted immediately

NOTE: similar thing happens when you make a mouse selection, then modify it using quick-edit keys (i.e. shift+right). The selected text is not copied and pasted immediately.

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jan 11, 2023
@zadjii-msft
Copy link
Member Author

zadjii-msft commented Jan 13, 2023

Lemme make sure I get this straight - when you modify the selection with mark mode (with copyOnSelect:true), the clipboard contents don't get immediately updated? They only get updated on the right-click (which we turn around and use to immediately paste)?


Hmm. Because TermControl::_TryHandleKeyBinding calls _core.TryMarkModeKeybinding then early-returns, without going through Interactivity so that _selectionNeedsToBeCopied can be updated. Hmm.

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jan 13, 2023
@github-actions
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view or the 📜action log for details.

Unrecognized words (1)

occured

Previously acknowledged words that are now absent Hirots inthread reingest :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the [email protected]:microsoft/terminal.git repository
on the dev/migrie/b/14464-copyOnSelect-moving-text branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/3940577809/attempts/1'
✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. If it doesn't work for you, you can manually add (one word per line) / remove items to expect.txt and the excludes.txt files.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@ozinka
Copy link

ozinka commented May 30, 2023

Sorry, I'm not very experienced in feature implementation workflow. Could someone explain to me which stage this issue is on?
I waited for the new release and fix but unfortunately, it's still not implemented :(

@zadjii-msft
Copy link
Member Author

Sorry, I'm not very experienced in feature implementation workflow. Could someone explain to me which stage this issue is on? I waited for the new release and fix but unfortunately, it's still not implemented :(

No worries - this one's just in a bit of a holding pattern. There was an edge case I didn't account for in my original fix. I haven't had time to loop back on this one since. So this isn't fixed in 1.18 yet. Hopefully I can double back on this in July. (If someone else wants to help sort out the edge case above, I'd be happy to have the help)

@carlos-zamora
Copy link
Member

Lemme make sure I get this straight - when you modify the selection with mark mode (with copyOnSelect:true), the clipboard contents don't get immediately updated? They only get updated on the right-click (which we turn around and use to immediately paste)?

Correct! Because if the clipboard contents got updated whenever you move the cursor, you'd copy so many " " to your clipboard! 😆

// copied this selection. GH#14464 demonstrates a scenario where the
// buffer contents might have changed since the selection was made,
// and copying here would cause weirdness.
if (_selectionNeedsToBeCopied || !copyOnSelect)
Copy link
Member

Choose a reason for hiding this comment

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

I don't quite get why this depends on CopyOnSelect... When would we ever want to copy text more than once?

@ozinka
Copy link

ozinka commented Jan 30, 2024

I waited for a long time this issue will be fixed and no. New version 1.20 doesn't contain fix for it. I wander why so small number of users confirmed this bug. This feature works ideal on putty, why it can't be fixed on MS Terminal? I believe it's pretty easy to fix.
I'm sorry, I'm not experienced developer, otherwhise I'd also contribute. If there is any volonteer to explain how I can do that, please guide me. I believe I can read this code to fix it.

@zadjii-msft
Copy link
Member Author

I've been working on another project for the last 6 months and have solidly cached this out. I'll probably loop around on all these open PRs after that gets out the door, but I honestly don't remember exactly the interaction that was weird about this fix. I know that it was related to #14635 (review) but I don't recall how the code flowed to cause that anymore.

@ozinka
Copy link

ozinka commented Jan 30, 2024

I've been working on another project for the last 6 months and have solidly cached this out. I'll probably loop around on all these open PRs after that gets out the door, but I honestly don't remember exactly the interaction that was weird about this fix. I know that it was related to #14635 (review) but I don't recall how the code flowed to cause that anymore.

In the nutshell the problem is that when copyOnSelect is active it does it twise: onSelect and onPaste (right click). It shouldn't do copy during onPaste operation. In putty, when you select anything, putty shows selection. When you select anything somewhre else and copy it, putty clears it's own selection and after that buffer contains new selection. Which is used for paste on right click.

I've read release notes and that's a huge of work. Just hope new version also include fix for this bug. )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically copy selection to clipboard is no longer working correctly with tmux
5 participants