vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Terminal: Copy on selection + new highlight in 1.68 copies previous term on CMD+F

Open vfonic opened this issue 3 years ago • 35 comments

Does this issue occur when all extensions are disabled?: Yes/No

  • VS Code Version: 1.68.0 (this issue didn't exist on 1.67.2)
  • OS Version: macOS Monterey 12.3.1

Steps to Reproduce:

  1. In settings.json enable: "terminal.integrated.copyOnSelection": true,
  2. Open integrated terminal
  3. Search for some term that exists in the terminal (that will be highlighted/selected)
  4. Focus on editor and type + copy some chunk of text
  5. Focus on terminal, press CMD+F and paste what you just copied

Expected:

The pasted term is the term you just copied

Actual:

The pasted term is the term you last searched for (in step 3).

Why this happens?

Because:

  1. When you press CMD+F in terminal, the terminal has pre-existing term typed in the search box (from your first search)
  2. Terminal uses this term to highlight all occurrences of such term in the terminal
  3. Highlighting the terms makes the terminal also copy this term to clipboard due to "terminal.integrated.copyOnSelection": true,

vfonic avatar Jun 13 '22 02:06 vfonic

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.68.0. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

vscodenpa avatar Jun 13 '22 02:06 vscodenpa

The described behavior is how it is expected to work. If you disagree, please explain what is expected and what is not in more detail. See also our issue reporting guidelines.

Happy Coding!

vscodenpa avatar Jun 14 '22 18:06 vscodenpa

@meganrogge I believe you might have misunderstood my issue. When pressing CMD+F, the old term is added to the clipboard and the old term is highlighted and searched for, not the new term that the user wanted to search for.

For example:

  1. You search for "pasta" in terminal.
  2. You copy word "donut"
  3. Press CMD+F
  4. Press CMD+V (to paste)
  5. The pasted word in search box would be "pasta"

Please try to follow the repro steps to see how this bug happens.

vfonic avatar Jun 14 '22 23:06 vfonic

@meganrogge this has been happening to me, too, and the repro that @vfonic describes is spot on. can you reopen this?

joelhock avatar Jun 15 '22 20:06 joelhock

I still think that's as designed because the find widget uses the current terminal selection as the input for find

meganrogge avatar Jun 15 '22 20:06 meganrogge

@meganrogge this isn't about using the current selection as the input for find, it's about any matches to what's in the find box overwriting the clipboard entry. this certainly wasn't the behavior in previous versions. here's a video to illustrate:

https://user-images.githubusercontent.com/7648957/173935510-bef58bf9-c0b9-49b8-81f6-c5bd8c364612.mov

joelhock avatar Jun 15 '22 21:06 joelhock

@meganrogge did you try following the repro steps?

vfonic avatar Jun 16 '22 02:06 vfonic

Thanks for the gif, yes we misunderstood. Re-searching after content is added to the terminal should not copy the text, only when the find is explicitly triggered.

Tyriar avatar Jun 16 '22 15:06 Tyriar

this will be pretty involved currently - think we should fix it when we let each terminal have it's own find widget, #145865 because we'd need to do something like this and currently the instance doesn't have access to the find widget (it's owned by the tabs view) Screen Shot 2022-06-27 at 1 38 59 PM

meganrogge avatar Jun 27 '22 17:06 meganrogge

Oh :/

I've downgraded in the meantime as this is a huge issue for my workflow.

I fully support terminal having its own search widget, because I'm also using some other customization that depends on "terminal being in focus" and that doesn't work when searching in terminal.

Thank you for looking into this!

vfonic avatar Jun 28 '22 00:06 vfonic

My two cents is that even when find is explicitly triggered, a found selection's text should not be copied to the clipboard--maybe that's an easier fix?

joelhock avatar Jul 11 '22 20:07 joelhock

Thanks for creating this issue, I've been bugged by "accidental" clipboard contamination with some random stuff and finally figured out where it's coming from. Hope it can be fixed soon.

movy avatar Aug 07 '22 11:08 movy

What is the current status? Abandoned or added to a milestone?

krasi-georgiev avatar Nov 28 '22 20:11 krasi-georgiev

still a pending bug in

Version: 1.79.0-insider Commit: f6be5461f8bc69013a605f5baea834651c6589fb Date: 2023-05-20T01:20:25.075Z Electron: 22.5.2 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Linux x64 5.15.0-72-generic

krasi-georgiev avatar Jun 06 '23 05:06 krasi-georgiev

and extremely annoying also, took me like 10 attempts to figure out why the terminal keeps searching for something I did not put into the search field.

movy avatar Jun 06 '23 08:06 movy

I think the problem lies in erroneous 'copy on selection' behaviour, when EACH focus on the terminal with active text selection copies the selected text again and again. The only time copying should be performed is when the selection ends (i.e. mouse up or whatever event is responsible for this), not each time terminal pane gets focus.

movy avatar Jun 13 '23 13:06 movy

Moreover! This bug extends much further:

  • in terminal pane trigger search field and start typing search string
  • observe how your clipboard is being repeatedly replaced each time new letter is typed, i.e. selection is extended.

My clipboard history after typing in terminal search field: image

See video below for explanation:

https://github.com/microsoft/vscode/assets/4336560/f30f214a-9f89-4b26-b130-1ae0f204cde6

movy avatar Jun 13 '23 14:06 movy

Can the maintainers update us on when can this be scheduled for a fix.

krasi-georgiev avatar Aug 07 '23 14:08 krasi-georgiev

unfortunately, the bug is still present.

When I leave the search box open and the terminal is set to copy on selection it frequently hijacks the clipboard and places the text in the search box in the clipboard.

Version: 1.86.0-insider Commit: df8db3a75a49b85c9636530a3557cdbc639f7bdc Date: 2024-01-01T05:35:59.858Z Electron: 27.1.3 ElectronBuildId: 25612240 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Linux x64 5.15.0-91-generic

krasi-georgiev avatar Jan 19 '24 10:01 krasi-georgiev

+1 for the most recent comment, noticed it yesterday as well, very frustrating

movy avatar Jan 19 '24 10:01 movy

@krasi-georgiev @movy any more info on the repro? I tried opening search, clicking between editor, terminal and search and couldn't get it to copy the text in the search box?

Tyriar avatar Jan 30 '24 19:01 Tyriar

this shows a repro:

https://github.com/microsoft/vscode/assets/7648957/c8e510b2-5bfb-48a8-8aff-06e957066c37

joelhock avatar Jan 30 '24 20:01 joelhock

Thanks I can repro, I think what's happening is the the find is doing another search when the content changes and since the find widget isn't active it's getting copied to the clipboard.

Tyriar avatar Jan 30 '24 21:01 Tyriar

@Tyriar

any more info on the repro?

Hey @Tyriar can you please tell me which of the repro steps I posted originally 2 years ago is confusing to you?

  1. In settings.json enable: "terminal.integrated.copyOnSelection": true,
  2. Open integrated terminal
  3. Search for some term that exists in the terminal (that will be highlighted/selected)
  4. Focus on editor and type + copy some chunk of text
  5. Focus on terminal, press CMD+F and paste what you just copied

Here's the screen recording showing exactly these repro steps causing the bug: https://github.com/microsoft/vscode/assets/67437/ff749c31-30b1-4564-be2a-6e9a2daaa555

BTW I tested on VS Code 1.85.2 stable, but I've seen that someone else already tested on the latest insiders build and that the bug is still present.

vfonic avatar Jan 31 '24 16:01 vfonic

@vfonic that bug was fixed in 1.86, @joelhock helped find the edge case that was missed.

Tyriar avatar Jan 31 '24 17:01 Tyriar

@Tyriar indeed! I just tested it on the VS Code Insiders and the bug I mentioned with my repro steps is no longer happening! Thank you! 🙏

vfonic avatar Jan 31 '24 18:01 vfonic

Finally! I was also struggling a lot in my workflow with this regression. Thanks a lot for fixing it! :pray: (and tnx @vfonic for reporting and providing repro instruction 🙂 )

Pictor13 avatar Feb 22 '24 18:02 Pictor13

Original steps do not reproduce, thus closing

meganrogge avatar Dec 09 '24 19:12 meganrogge

@meganrogge, yes, they do reproduce. At least on latest stable: 1.95.3

I don't have other version at hand.

vfonic avatar Dec 09 '24 20:12 vfonic

Just upgraded to 1.97.0-1736766348 and no change the find text takes over the clipboard, see the video

https://github.com/user-attachments/assets/0bc98e29-0895-4808-ae80-52d570de32b1

krasi-georgiev avatar Jan 13 '25 22:01 krasi-georgiev