microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
161.79k stars 28.44k forks source link

[folding] Move line up/down should skip over folded regions or folded sections #63972

Open ali80 opened 5 years ago

ali80 commented 5 years ago

I think when code is in a folded region or section it should never unfold unless explicitly commanded, so if you are moving a line using move command, the line should skip over both folded regions and folded sections Steps to Reproduce:

  1. create a folded region using #region #endregion
  2. fold some code section
  3. move a line using alt+up/down over the folded region/section vscodemovelinebug

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

vscodebot[bot] commented 5 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

spott commented 4 years ago

I want to add my support for this problem. It is particularly annoying when using the vim keybindings, as right after the fold is closed (using zc), the mouse is above the just folded code, so if I want to move down below the folded region, it automatically unfolds as I do so.

Frug commented 4 years ago

As someone who uses the keyboard to navigate (vim plugin is a godsend) it's very frustrating that collapsed regions auto expand when I try to move past them. If the collapsed region is big I totally lose my place on the page.

beaugunderson commented 4 years ago

@Frug you can set the vim.foldfix setting to true if you're using the vim plugin and it will fix this annoyance for you 😄️ (this works with simple movement but I'm not sure if it works with moving lines up and down, which is what this issue is about)

minig0d commented 3 years ago

Any solution to the issue without an extension? I frequently use the alt up/down (editor.action.moveLinesUpAction / editor.action.moveLinesDownAction) shortcuts and this may be one of the most annoying counter-intuitive behaviors of VSC... Honestly, if you're moving a line of text (or a block), would anyone really want folded section to unfold? I mean, isn't the reason we are folding the section because we are not actively dealing with it?

ssmooncoder commented 3 years ago

Every time I try to use folding, I'm reminded how buggy and unintuitive it is and why I'd disabled folding altogether.

The feature needs a rework but I think it may have been abandoned, since this issue has now been open for +2 years.

BettyJJ commented 3 years ago

I also need this feature.

BTW: I don't think it's possible to do this in a extension, since VSC doesn't seem to provide API to access the folded ranges. Unless you implement the folding feature all over again by yourself.

unikcc commented 2 years ago

@Frug you can set the vim.foldfix setting to true if you're using the vim plugin and it will fix this annoyance for you 😄️ (this works with simple movement but I'm not sure if it works with moving lines up and down, which is what this issue is about)

Yes this is what I'm looking for. Thank you!

fontseca commented 2 years ago

@Frug you can set the vim.foldfix setting to true if you're using the vim plugin and it will fix this annoyance for you 😄️ (this works with simple movement but I'm not sure if it works with moving lines up and down, which is what this issue is about)

I used vim.foldfix but then when I try 10j or 100k I have a cursor delay due to the movement. I don´t know how to solve it.

filmerjarred commented 2 years ago

I also need this feature.

BTW: I don't think it's possible to do this in a extension, since VSC doesn't seem to provide API to access the folded ranges. Unless you implement the folding feature all over again by yourself.

Through experimentation it seems that vscode.window.activeTextEditor.visibleRanges represents currently visible folded ranges, which one could use to know what to skip.

If someone with more knowledge can confirm this is accurate and there's no reason an extension couldn't use this info to know which ranges to skip when moving lines up and down I'd be happy to write it.

paulmsmith commented 2 years ago

I'd love this to be resolved. It's not major but it is mighty frustrating, makes the feature of 'move line' much less powerful.

Did this functionality ever existing VSCode or am I remembering Sublime/Textmate?

jzyrobert commented 2 years ago

I've had a look at the code starting from https://github.com/microsoft/vscode/blob/bc403a0b71f0013c7d3cdb2196e9acff32650095/src/vs/editor/contrib/linesOperations/browser/moveLinesCommand.ts#L43 and implementing this would require some major logic changes (the logic hasn't changed in 5-7 years) as currently it assumes only 1 line will have to move: https://github.com/microsoft/vscode/blob/bc403a0b71f0013c7d3cdb2196e9acff32650095/src/vs/editor/contrib/linesOperations/browser/moveLinesCommand.ts#L84 with the indentation checking/edits also making those assumptions https://github.com/microsoft/vscode/blob/bc403a0b71f0013c7d3cdb2196e9acff32650095/src/vs/editor/contrib/linesOperations/browser/moveLinesCommand.ts#L114-L115 https://github.com/microsoft/vscode/blob/bc403a0b71f0013c7d3cdb2196e9acff32650095/src/vs/editor/contrib/linesOperations/browser/moveLinesCommand.ts#L297-L300

An implementation question would also be how to add checking whether a line belongs to a fold.

Once you have the folding ranges you could then update the logic from "Move 1 line" to "Move n lines".

@aeschli I also noticed that moving down and up don't actually perform the same logic.

https://user-images.githubusercontent.com/20613660/175808303-ee64e565-dde1-48b4-a6f5-a0faf0e7c4c5.mp4

So moving the statement down and moving the bracket up should theoretically be the same but results in different edits. Is this a bug or intended behaviour?

starball5 commented 1 year ago

Related on Stack Overflow: How can I move lines or folded regions before or after other folded regions?.

tommaso-bissoli commented 1 month ago

Atom Editor had the feature out of the box... -.- -.- -.-

You could move an entire folded region up and down through other collapsed regions with the same single move up and down command...

Can't anyone on VSCode teams just take the code from Atom and adapt it fo Vscode?

It's really frustrating...