Skip to content

editor.removeManualFoldingRanges should support empty selection #266597

Closed

Description

@RedCMD

Folding ranges will sometimes break when pasting over Folded ranges
the ranges will appear in the wrong location/don't show up at all
editor.removeManualFoldingRanges does not fix it
nor does changing the language and sometimes even reloading
still happens even with "editor.foldingStrategy": "indentation"

found some solid repo steps
happens when pasting text over already recursively collapsed text
doesn't have to be JSON, happens in plaintext and TypeScript etc as well

Steps to Reproduce:

  1. open large file with many foldings
    https://github.com/RedCMD/TmLanguage-Syntax-Highlighter/blob/main/syntaxes/regex.tmLanguage.json
  2. recursively collapse most of the file (with middle-click/scroll-click/button 3)
  3. paste a different large file over top
    https://github.com/RedCMD/redcmd.rascal-syntax-highlighter/blob/master/syntaxes/rascal.tmLanguage.json
  4. witness broken foldings left behind
20250906-0634-04.8416172.mp4

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.104.0
  • OS Version: Windows 11

Activity

  1. changed the title [-]Folding ranges breaking on paste[/-] [+]Folded Folding ranges breaking on paste[/+] on Sep 14, 2025
  2. changed the title [-]Folded Folding ranges breaking on paste[/-] [+]editor.removeManualFoldingRanges should support empty selection[/+] on Dec 10, 2025
  3. added
    editor-folding
    bug
    on Dec 10, 2025
  4. aeschli commented on Dec 10, 2025

    @aeschli
    Contributor

    You currently need to select the full text and run 'editor.removeManualFoldingRanges'
    We should support the empt selection that deletes all manual folding ranges

  5. added
    team-low-hanging
    on Dec 10, 2025
  6. RedCMD commented on Dec 10, 2025

    @RedCMD
    ContributorAuthor

    Martin Aeschlimann (@aeschli) should make a new issue for supporting editor.removeManualFoldingRanges with empty selection
    as that is not the issue I'm reporting
    I'm reporting that folding ranges break when pasting large amount of text

  7. aeschli commented on Dec 11, 2025

    @aeschli
    Contributor

    We can change the label back, but I don't know how we would solve that in the near future. It's a sensitive area as user don't want to lose folded ranges.

  8. aeschli commented on Dec 11, 2025

    @aeschli
    Contributor

    Also see #201431

  9. RedCMD commented on Dec 16, 2025

    @RedCMD
    ContributorAuthor

    having a look into editor.removeManualFoldingRanges

    invoke(foldingController: FoldingController, foldingModel: FoldingModel, editor: ICodeEditor): void {
    const selections = editor.getSelections();
    if (selections) {
    const ranges: ILineRange[] = [];
    for (const selection of selections) {
    const { startLineNumber, endLineNumber } = selection;
    ranges.push(endLineNumber >= startLineNumber ? { startLineNumber, endLineNumber } : { endLineNumber, startLineNumber });
    }
    foldingModel.removeManualRanges(ranges);
    foldingController.triggerFoldingModelChanged();
    }
    }
    }

    We should support the empty selection that deletes all manual folding ranges

    currently it does support the empty selection
    in that it removes every range that intersects with the cursor
    if no selection is made editor.getSelections() returns a empty 0width selection

    so we could detect this single empty selection and replace it with a full document range selection editor.getModel()!.getFullModelRange()
    but users probably already expect the current behaviour
    so idk
    maybe detect if no range intersects the empty selection?

  10. added 2 commits that reference this issue on Mar 25, 2026
    542ce16
    8b259d5
  11. yogeshwaran-c commented on Mar 25, 2026

    @yogeshwaran-c
    Contributor

    Implemented a fix in #304793 that combines both approaches suggested here:

    • Cursor on a manual folding range: Removes only the innermost manual range (peels one layer at a time, per RedCMD (@RedCMD)'s feedback)
    • Cursor NOT on any manual range: Removes all manual folding ranges in the document (per Martin Aeschlimann (@aeschli)'s suggestion)

    This way the command is always useful regardless of cursor position, and the behavior is intuitive in both cases.

  12. added
    unreleased
    on Jul 29, 2026
  13. added a commit that references this issue on Jul 29, 2026
    e85daf1
  14. added
    insiders-released
    and removed
    unreleased
    on Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugeditor-foldinginsiders-releasedteam-low-hangingverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions