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

[folding] Incorrect indent level being folded #3425

Closed
Tyriar opened this issue Feb 24, 2016 · 2 comments
Closed

[folding] Incorrect indent level being folded #3425

Tyriar opened this issue Feb 24, 2016 · 2 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-folding Editor code folding issues important Issue identified as high-priority verified Verification succeeded
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented Feb 24, 2016

#2994

With this Java file:

package com.growingwiththeweb.sorting;

public class BubbleSort {
    public static void sort(Integer[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 1; j < array.length - i; j++) {
                if (array[j - 1] > array[j]) {
                    swap(array, j, j - 1);
                }
            }
        }
    }

    private static void swap(Integer[] array, int a, int b) {
        Integer temp = array[a];
        array[a] = array[b];
        array[b] = temp;
    }
}

Selecting line number 8 (swap(array, j, j - 1)) and hitting ctrl+shift+[ folds the wrong level:

image

Adding another if statement within that if again folds 1 level above the correct level.

@Tyriar Tyriar added bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority editor-folding Editor code folding issues labels Feb 24, 2016
@Tyriar Tyriar changed the title Incorrect indent level being folded [folding] Incorrect indent level being folded Feb 24, 2016
@tht13
Copy link
Contributor

tht13 commented Feb 25, 2016

A further issue here is that if you perform the fold it will not fold, for example:

function foo() {
    bar();
}

However if you add a second line like this:

function foo() {
    bar();
    fux();
}

If you fold/unfold and then remove the new second line and attempt to fold the single line, the folding works. (The same happens with your example above, add a second line in that if statement, fold/unfold it, remove the line, it will then fold correctly.

This is caused by this.decorations returns a two line range for single line collapse regions, so for line 8 (7, zero counting) where you trigger the fold, it will return range: {startLine: 7, endLine: 8} rather than range: {startLine: 7, endLine: 7}.
The added line in the return range then causes the if statement in L374 to fail and in you case it reverts to the surrounding fold range. Or in my example simply does not fold.

I have been unable to debug how these ranges are generated but I am sure @aeschli knows 😄

Hope this helps 👍

@aeschli
Copy link
Contributor

aeschli commented Feb 25, 2016

duplicate of #3398

I tested the fix of #3398 with your examples. Thanks @tht13 and @Tyriar !

@aeschli aeschli closed this as completed Feb 25, 2016
@aeschli aeschli assigned joaomoreno and unassigned aeschli Feb 26, 2016
@aeschli aeschli added this to the Feb 2016 milestone Feb 26, 2016
@isidorn isidorn added the verified Verification succeeded label Mar 18, 2016
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug editor-folding Editor code folding issues important Issue identified as high-priority verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants