8000 Add indent based code folding by aeschli · Pull Request #2971 · microsoft/vscode · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add indent based code folding #2971

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

Merged
merged 22 commits into from
Feb 12, 2016
Merged

Add indent based code folding #2971

merged 22 commits into from
Feb 12, 2016

Conversation

aeschli
Copy link
Contributor
@aeschli aeschli commented Feb 12, 2016

No description provided.

@aeschli aeschli added this to the Feb 2016 milestone Feb 12, 2016
@aeschli aeschli self-assigned this Feb 12, 2016
@aeschli
Copy link
Contributor Author
aeschli commented Feb 12, 2016

@alexandrudima Alex, FYI

aeschli added a commit that referenced this pull request Feb 12, 2016
@aeschli aeschli merged commit e7e8ed2 into master Feb 12, 2016
@aeschli aeschli deleted the aeschli-folding branch April 8, 2016 21:37
@aminroosta
Copy link

@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
Copy link
aminroosta commented Jul 20, 2016

@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
Copy link
Contributor Author
aeschli commented Jul 21, 2016

@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
Member

@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
Copy link
Member
rebornix commented Jul 21, 2016

@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. @aeschli what do you think?

@aminroosta
Copy link

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

@sandy081
Copy link
Member

@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
Member

After discussing with @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
0