Fold multiple blocks #611

Closed
ghost opened this Issue Jan 9, 2012 · 2 comments

Comments

Projects
None yet
1 participant
@ghost

ghost commented Jan 9, 2012

I have a CoffeeScript file that have many functions like this:

obj =

  "function a": ->
    ...
  "function b": ->
    ...
  "function c": ->
    ...
  "function d": ->
    ...

I wonder if it's possible to fold all of them at once instead of me having to manually fold each one of them since they are hundreds.

But only these "first level" functions. Not the functions declared inside them.

If not, could a feature be added to fold level specific blocks in selected text.

Eg.

  1. Select text
  2. Choose which level to fold (1, 2, 3 etc)

Where 1 means all top level blocks would be fold, 2 means all top and second level blocks (eg. functions inside top level functions) and so on.
@gissues:{"order":11.180124223602768,"status":"backlog"}

Owner

nightwing commented Jun 26, 2015

Now it is possible to fold all functions in obj by putting cursor somewhere in obj and pressing alt-0, or shift clicking on a widget of obj.

We could add fold at level either based on indentation

    var foldAtDepth = function(depth) {
        var session = editor.session;
        var indent = depth * session.getTabString().length;

        for (var row = 0, l = session.getLength(); row < l; row++) {
            if (session.foldWidgets[row] === undefined)
                session.foldWidgets[row] = session.getFoldWidget(row);
            if (session.foldWidgets[row] === "start") {
                if (session.getLine(row).search(/\S/) !== indent)
                    continue;
                var range = session.getFoldWidgetRange(row);
                if (range) {
                    var fold = session.addFold("...", range);
                    row = range.end.row;
                }
            }
        }
    };

or the nesting

    var foldAtDepth = function(depth) {
        var session = editor.session;
        var stack = [];

        for (var row = 0, l = session.getLength(); row < l; row++) {
            var last = stack[stack.length - 1]
            while (stack.length && last <= row) {
                stack.pop();
                last = stack[stack.length - 1];                
            }
            if (session.foldWidgets[row] === undefined)
                session.foldWidgets[row] = session.getFoldWidget(row);
            if (session.foldWidgets[row] === "start") {
                var range = session.getFoldWidgetRange(row);
                if (range) {
                    if (stack.length < depth) {
                        stack.push(range.end.row);
                    } else {
                        var fold = session.addFold("...", range);
                        row = range.end.row;
                    }                    
                }
            }
        }
    };

see https://groups.google.com/forum/#!topic/ace-discuss/JfMdCm1K8Qc

Owner

nightwing commented Jun 18, 2017

Closing since the existing commands seem to work well enough, if you think foldAtDepth commands are still needed, lease comment.

@nightwing nightwing closed this Jun 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment