NoaHammer
NoaHammer

Reputation: 352

Copy & paste folded text in Visual Studio Code

Given the following text

Node1_L1
  Node1_L2
  Node2_L2
Node2_L1
  Node3_L2
    Node1_L3
    Node2_L3
  Node4_L2
    Node3_L3
    Node4_L3
Node3_L1
  Node5_L2
  Node6_L2  

I can use vscode's built-in folding feature to fold it to look like so

+ Node1_L1
  Node2_L1
+   Node3_L2
+   Node4_L2
  Node3_L1
    Node5_L2
    Node6_L2

but when I now select the folded text and copy & paste it then it actually grabbed all text - also the hidden one. The result of copy & paste of the first 4 lines of the folded text above would therefore be

Node1_L1
  Node1_L2
  Node2_L2
Node2_L1
  Node3_L2
    Node1_L3
    Node2_L3
  Node4_L2

whereas I would like to have

Node1_L1
Node2_L1
  Node3_L2
  Node4_L2  

Hope that makes sense and someone knows a way to do it. Thanks!

Upvotes: 22

Views: 5338

Answers (2)

ta32
ta32

Reputation: 148

If the selection doesn't include the new line and carriage return, folded content will not be copied.

The selection must go to the start of the next line to select the folded text ( hidden text )

enter image description here

https://github.com/Microsoft/vscode/issues/41922#issuecomment-359368290

The op actually wants to select 'unfolded' text ignoring the folded text so they need to use a multi-line select where each selection will span a single line

Upvotes: 1

DAXaholic
DAXaholic

Reputation: 35408

Maybe there is another way of doing it but a workaround seems to be using block selection with multiple cursors - see the GIF

Block selection to copy only top level folding text

Upvotes: 14

Related Questions