Skip to content

Add indent based code folding - #2971

Merged
Martin Aeschlimann (aeschli) merged 22 commits into
masterfrom
aeschli-folding
Feb 12, 2016
Merged

Martin Aeschlimann (aeschli) merged 22 commits into
masterfrom
aeschli-folding

Conversation

@aeschli

Copy link
Copy Markdown
Contributor

No description provided.

@aeschli

Copy link
Copy Markdown
Contributor Author

alexandrudima Alex, FYI

Martin Aeschlimann (aeschli) added a commit that referenced this pull request Feb 12, 2016
@aeschli
Martin Aeschlimann (aeschli) deleted the aeschli-folding branch April 8, 2016 21:37
@aminroosta

Copy link
Copy Markdown

Martin Aeschlimann (@aeschli)

Is there a way for extensions to figure out which parts of code are folded?
For example vim extensions need this to properly move the cursor when different parts of code are being folded.

I think this is not possible right now and if that's the case, what do you think about exposing getHiddenAreas() function to extensions?

@aminroosta

Amin Roosta (aminroosta) commented Jul 20, 2016 •

Copy link
Copy Markdown

Martin Aeschlimann (@aeschli) atom editor uses the same indentation based folding but also includes the line after a fold-range with a foldEndPattern regex check. The regex pattern is different for each language.

For css: 'foldEndPattern': '(?<!\\*)\\*\\*/|^\\s*\\}|\\/*\\s*@end\\s*\\*\\/'
For js : 'foldEndPattern': '^\\s*\\}|^\\s*\\]|^\\s*\\)'

Some language extensions in vs code already have this pattern (php) but not all of them.

Clearly this needs to be added to all language extensions but it doesn't seem to be easy.
Specially because each extension has it's own syntaxes files (even with different formats).

Do you think supporting C based languages with this approach is a good idea (just for now)?
Should i send a PR only supporting languages with block folding ( { } ).

@aeschli

Martin Aeschlimann (aeschli) commented Jul 21, 2016 •

Copy link
Copy Markdown
Contributor Author

Amin Roosta (@aminroosta) There is currently no API in the extension host to find out about folded regions. But there is ongoing work for improving VIM support to enable cursor operations: see #9143

Supporting folding end patterns is a good suggestion. For now we have no work planned as other issues have higher priority.

@rebornix

Copy link
Copy Markdown
Contributor

Amin Roosta (@aminroosta) we already have new APIs for cursor movement across visible lines, you can run

vscode.commands.executeCommand("cursorMove", {
      to: "lineUo", // or "lineDown"
      noOfLines: 1
    });

to move across folded lines.

@rebornix

Peng Lyu (rebornix) commented Jul 21, 2016 •

Copy link
Copy Markdown
Contributor

Amin Roosta (@aminroosta) current implementation of VSCodeVim is not handling cursor moving correctly. We are changing cursor position ourselves, which breaks the cursor moving in folded code.

There are several commands in Code for cursor moving, eg, cursorLeft, cursorLeftSelect, etc. But they are not working perfectly the same as Vim does.

Take below text as example, | represents the position of the cursor

abc|
de
fghi

if you move cursor down twice, the result in Vim is

abc
de
fghi|

while in VS Code with no extensions, the result will be

abc
de
fg|hi

This is mainly why we are calculating ourselves but not leveraging VS Code commands. If we keep using VS Code's commands, the result of cursor moving is not always correct. If we do it ourselves, we may need the information about folding area. Martin Aeschlimann (@aeschli) what do you think?

@aminroosta

Copy link
Copy Markdown

Martin Aeschlimann (@aeschli) I just found another use case :-), implementing toggle-fold command.
without information on folding areas that would be impossible.

@sandy081

Copy link
Copy Markdown
Member

Peng Lyu (@rebornix) I am seeing following behavior in VS Code and it is similar to Vim behavior you mentioned in your example

jul-22-2016 11-10-27

@sandy081

Copy link
Copy Markdown
Member

After discussing with Peng Lyu (@rebornix) fixing the issue #9619 will let Vim to completely use VS Code apis for cursor movements, thereby, fixing the folding issue automatically.

@github-actions github-actions Bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants