<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="133425257" data-permission-text="Title is private" data-url="https://github.com/microsoft/vscode/issues/2994" data-hovercard-type="issue" data-hovercard-url="/microsoft/vscode/issues/2994/hovercard" href="https://github.com/microsoft/vscode/issues/2994">#2994</a></p>
<p dir="auto">With this Java file:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package com.growingwiththeweb.sorting;

public class BubbleSort {
    public static void sort(Integer[] array) {
        for (int i = 0; i &lt; array.length - 1; i++) {
            for (int j = 1; j &lt; array.length - i; j++) {
                if (array[j - 1] &gt; 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;
    }
}"><pre class="notranslate"><span class="pl-k">package</span> <span class="pl-s1">com</span>.<span class="pl-s1">growingwiththeweb</span>.<span class="pl-s1">sorting</span>;

<span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">BubbleSort</span> {
    <span class="pl-k">public</span> <span class="pl-k">static</span> <span class="pl-smi">void</span> <span class="pl-en">sort</span>(<span class="pl-smi">Integer</span>[] <span class="pl-s1">array</span>) {
        <span class="pl-k">for</span> (<span class="pl-smi">int</span> <span class="pl-s1">i</span> = <span class="pl-c1">0</span>; <span class="pl-s1">i</span> &lt; <span class="pl-s1">array</span>.<span class="pl-s1">length</span> - <span class="pl-c1">1</span>; <span class="pl-s1">i</span>++) {
            <span class="pl-k">for</span> (<span class="pl-smi">int</span> <span class="pl-s1">j</span> = <span class="pl-c1">1</span>; <span class="pl-s1">j</span> &lt; <span class="pl-s1">array</span>.<span class="pl-s1">length</span> - <span class="pl-s1">i</span>; <span class="pl-s1">j</span>++) {
                <span class="pl-k">if</span> (<span class="pl-s1">array</span>[<span class="pl-s1">j</span> - <span class="pl-c1">1</span>] &gt; <span class="pl-s1">array</span>[<span class="pl-s1">j</span>]) {
                    <span class="pl-en">swap</span>(<span class="pl-s1">array</span>, <span class="pl-s1">j</span>, <span class="pl-s1">j</span> - <span class="pl-c1">1</span>);
                }
            }
        }
    }

    <span class="pl-k">private</span> <span class="pl-k">static</span> <span class="pl-smi">void</span> <span class="pl-en">swap</span>(<span class="pl-smi">Integer</span>[] <span class="pl-s1">array</span>, <span class="pl-smi">int</span> <span class="pl-s1">a</span>, <span class="pl-smi">int</span> <span class="pl-s1">b</span>) {
        <span class="pl-smi">Integer</span> <span class="pl-s1">temp</span> = <span class="pl-s1">array</span>[<span class="pl-s1">a</span>];
        <span class="pl-s1">array</span>[<span class="pl-s1">a</span>] = <span class="pl-s1">array</span>[<span class="pl-s1">b</span>];
        <span class="pl-s1">array</span>[<span class="pl-s1">b</span>] = <span class="pl-s1">temp</span>;
    }
}</pre></div>
<p dir="auto">Selecting line number 8 (<code class="notranslate">swap(array, j, j - 1)</code>) and hitting <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>[</kbd> folds the wrong level:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/2193314/13299243/26bcb66e-daef-11e5-9263-b274a81787e2.png"><img src="https://cloud.githubusercontent.com/assets/2193314/13299243/26bcb66e-daef-11e5-9263-b274a81787e2.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">Adding another if statement within that <code class="notranslate">if</code> again folds 1 level above the correct level.</p>
<p dir="auto">Testing <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="133425257" data-permission-text="Title is private" data-url="https://github.com/microsoft/vscode/issues/2994" data-hovercard-type="issue" data-hovercard-url="/microsoft/vscode/issues/2994/hovercard" href="https://github.com/microsoft/vscode/issues/2994">#2994</a></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/22350/13283270/3de70c92-daed-11e5-84dd-766846602e2a.gif"><img src="https://cloud.githubusercontent.com/assets/22350/13283270/3de70c92-daed-11e5-84dd-766846602e2a.gif" alt="bug" data-animated-image="" style="max-width: 100%;"></a></p>
<p dir="auto">When my cursor is at line <code class="notranslate">266</code> and run the Fold action, the folding block that starts at line <code class="notranslate">263</code> gets folded. I expected that the block that starts at line <code class="notranslate">265</code> to be folded instead.</p>
<p dir="auto">When the cursor is at line <code class="notranslate">265</code>, behaviour is as expected, by the way.</p>