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

Handle pasting code from column selection specially #5940

Open
alexdima opened this issue Apr 28, 2016 · 26 comments
Open

Handle pasting code from column selection specially #5940

alexdima opened this issue Apr 28, 2016 · 26 comments
Labels
editor-columnselect Editor column selection issues feature-request Request for new features or functionality
Milestone

Comments

@alexdima
Copy link
Member

alexdima commented Apr 28, 2016

#1515 (comment)

From @seva0stapenko


Tried column selection in VSCode 1.0. Well, rectangular selection does work, cutting and pasting back also works, but that's about it.
Cutting and pasting into a different part of the code does not work as expected. Both Notepad++ and VS remember that copied text was a rectangular block and paste it as a rectangular block.
VSCode treats copied block just like a regular text, so pasting it anywhere outside of the current multi-cursor context would create a mess.
It's good that the feature is being worked on, but it's not fully baked yet.


Addition from @hediet

This is (still) the current behavior of VS Code. The copied/pasted text matches the selection:

recording

However, the copied/pasted text should match this selection:

recording

See also #43145 for how other editors handle it.

@alexdima alexdima self-assigned this Apr 28, 2016
@jaygeek
Copy link

jaygeek commented May 16, 2016

+1

@alexdima alexdima added the bug Issue identified by VS Code Team member as probable bug label May 23, 2016
@caramorsimon
Copy link

+1
copy/paste rectangular blocks is a regular occurrence eg, to duplicate some text to create 2 columns (and the 2nd column to appear starting from whatever floating top left the cursor is at (even beyond the nominal line ending)
To go from

something a
something bb
something cccc

to

something a        a
something bb       bb
something cccc     cccc

[when the line count, text length/complexity high it is an essential feature in a code editor of substance as many others have commented in the original column select issue]

@chen56
Copy link

chen56 commented Feb 25, 2017

+1

@chen56
Copy link

chen56 commented Feb 25, 2017

Paste the column has been support,cool ,

  1. shift+alt select column
  2. ctrl +c / ctrl +d , cool
    version:1.9.1

@AndrewArace
Copy link

@chen56 not following, still isn't working, version 1.10.1

@alexdima alexdima added this to the Backlog milestone Mar 8, 2017
@alexdima alexdima added the editor-multicursor Editor multiple cursor issues label Mar 8, 2017
@alexdima alexdima added editor-columnselect Editor column selection issues and removed editor-multicursor Editor multiple cursor issues labels Sep 28, 2017
@alexdima alexdima added feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug labels Dec 18, 2017
@douglaswaugh
Copy link

I would definitely like this feature. There was some talk of it in #1515 but that issue seems to have been closed before it was resolved.

@joaociocca
Copy link

joaociocca commented Jan 11, 2018

so, we're on 1.18.1 and this is still not working as intended =(

@Himura2la
Copy link

Himura2la commented Jan 13, 2018

Looking forward to this feature

@justingrant
Copy link
Contributor

I don't get it-- what's the point of rectangular selection if you can't paste a rectangular selection into other code? This has been a useful feature of Visual Studio editors since Visual C++ in the early '90s.

@Trahloc
Copy link

Trahloc commented May 11, 2018

Assignment removal 21 days ago, that's unfortunate.

@ghost
Copy link

ghost commented Jun 14, 2018

I'd like to see this feature work just like VS and Notepad++. Until it does, column/block copy is pretty much useless.

@stefjoosten
Copy link

+1
Pity to see this issue closed. :-( The feature is much needed...

@tuljmdev
Copy link

+1
Would love to see this work the same as VS

@tksuoran
Copy link

+1

I regularly use and need this feature. Please implement.

@pbb72
Copy link

pbb72 commented Oct 1, 2018

This was not immediately obvious to me, so it may help other people to know this. While not an ideal solution, you can easily paste columns by creating a new column selection and pasting into that.

  1. Select the source column in the normal way (by positioning the cursor in one corner of the rectangle, and then alt+shift+click on the opposite corner, then ctrl+c to copy).
  2. Create a new column selection on the desired destination, again with alt+shift+click. This column can be 0-width if you want to insert your pasted code.
  3. Simply paste the code with ctrl+v.

@smennesson
Copy link

In the case you would be surprised like me, pbb72's solution only works if you select the same exact number of lines between the copied selection and the target selection!

So for example, if you copy 3 lines from column selection, and then try to paste it on 4 lines, instead of pasting on the 3 first lines, it will create a mess (copy the full selection on each line).

Coming from Intellij IDEs it's quite surprising for me. Would be good to support it on Vscode.

@ericchase
Copy link

If someone on the vscode team could polish this feature, that would be greatly appreciated.
Visual Studio pro's box selection is so much better.

@ArashPartow
Copy link

ArashPartow commented May 19, 2019

More examples of this problem can be found here: #43145

@jozilla
Copy link

jozilla commented Feb 6, 2020

This even works in TextEdit on Mac (default built-in editor)...

@jtakalai
Copy link

It actually used to work for me, but was broken now.

@muendelezaji
Copy link

In the case you would be surprised like me, pbb72's solution only works if you select the same exact number of lines between the copied selection and the target selection!

So for example, if you copy 3 lines from column selection, and then try to paste it on 4 lines, instead of pasting on the 3 first lines, it will create a mess (copy the full selection on each line).

Coming from Intellij IDEs it's quite surprising for me. Would be good to support it on Vscode.

Just encountered this again, and note that even though pasting columns has since been implemented, it only seems to work correctly for equal line counts.

Pasting a mismatching number of lines still causes the inconvenience described above.

@peteraritchie
Copy link

I think the way this is performed in VSCode is a frustrating UX. But, it does work. The only way I could get it to copy a rectangle or columns is:

  1. Click the top left corner of what you want to copy.
  2. Shift+Alt+click the bottom right corner (or click and drag-select)
  3. Ctrl+C
  4. Click the top of where you want to paste.
  5. Shift+Alt+Click the bottom ensuring the number of rows is the same as what you copied (can be one column, regardless of the source).
  6. Ctrl+V.

et voila

In the destination, if the top-right is in the same column as the bottom right, you can see how many rows are selected in the bottom status bar to the right of the spaces per tab and the encoding (e.g. UTF-8)

@gazzar
Copy link

gazzar commented Dec 9, 2020

@peteraritchie Nope. Well actually yes it can work in limited circumstances, provided neither the block you're cutting and the destination location don't extend beyond the end of any lines between the start and end of selection. When that's the case, the number of rows selected in the source won't include the blank lines, which you would want to be treated as blank lines in the block. The only way that it will work is if virtual whitespace is treated explicitly.

@icetbr
Copy link

icetbr commented Nov 19, 2021

Meanwhile, this might solve some of your headaches. The author just added an option to replicate the current line white space.

john-guo/columnpaste#5
https://marketplace.visualstudio.com/items?itemName=johnguo.columnpaste

@krisutofu
Copy link

krisutofu commented Sep 19, 2022

Could someone explain to me the extent of this issue? Is this (#5940) and #13960 working with tabs and other multi-width characters in the same way, virtual navigation?

Do these issues propose multi-width whitespace to be filled up with "virtual spaces"? I mean, being able to navigate (or click) INTO multi-space whitespace like tabs (or stretched character space) and being able to input characters there, and inserting physical space when necessary.

I know, some people will complain about using spaces for this case but this is not the point. A tab character is a control character. Space is not a control character. I mean control characters for a future, where people wouldn't hard-code visual presentation anymore inside code because tools would be doing it automatically. I would even consider virtual space to be some sort of control character but which is not serialized.

An extension could treat the tab character as an instruction for the renderer to align characters behind the tab (or double tab) character in consecutive lines with virtual spaces. These virtual spaces may be copied, pasted as physical or virtual spaces but not saved to the file. Instead of fixed modulo behaviour the tab would be of dynamic length depending on context. When being split by a typed character, only the left part would be filled with physical spaces. An extension, which would like to implement that, would require multi-width characters to be filled with virtual spaces automatically, also so that people can navigate in virtual coordinates instead of physical unicode characters stored in the text.
(EDIT: though contrary to the old-school virtual space, the cursor would still wrap around to the beginning of the next line when pressing CTRL+RightArrow at the last non-whitespace character of a line, or just when the cursor is at the boundary between virtual space and non-virtual space.)

@ArashPartow
Copy link

@krisutofu #43145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor-columnselect Editor column selection issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests