Skip to content

[api] Allow extensions to determine if a position is within a fold #81498

Closed

Description

@costincaraivan

This has been the most demanded feature of VSCodeVim: VSCodeVim/Vim#1004 for over 3 years.

The main problem with Folds and Vim is that some motions will skip right over folded areas (like moving up/down). We need to know if we are in a folded area so we can iterate these motions until we are out of the fold.

An API like vscode.window.activeTextEditor.getAllFoldedRegions(): vscode.Range[] would be ideal.

An API like vscode.window.activeTextEditor.isPositionInFold(position: vscode.Position): boolean would also be great.


This is technically a duplicate for 22276, but that was closed because the roadmap at the time couldn't include this ticket.

Maybe it's time to revisit this? It has been blocking the most demanded feature of one of the most popular plugins out there, for 3+ years.

Activity

  1. vscodebot commented on Sep 26, 2019

    @vscodebot

    (Experimental duplicate detection)
    Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

  2. MondoGao commented on Sep 27, 2019

    @MondoGao

    It's pretty annoying when you try to use some stuff like '#region', hope I had some time to fix this.

  3. fatfatson commented on Sep 27, 2019

    @fatfatson

    vote +1

  4. aminroosta commented on Sep 27, 2019

    @aminroosta

    please see alexandrudima comment on this issue, he summarizes the core problem perfectly
    #22276 (comment)

    here is the TLDR:

    • extensions run in a separate process
    • any reading API must be synchronous and must be pushed eagerly by the UI process to the extension host.
    • in other words, if we have a TextEditor.selection API, we must proactively push the selection, every time it changes, from the UI process to the extension host, even if there is an extension interested in reading the selection or not.
  5. lnicola commented on Sep 27, 2019

    @lnicola
    Contributor

    Couldn't extensions express interest in using this information, so that the UI process knows whether it should do that or not?

    Also, Code is firing a telemetry event on every arrow press, and I imagine that's not much better.

  6. aminroosta commented on Sep 27, 2019

    @aminroosta

    in the editor core, most of the code is kept in dark about the existance of a view model or about the existance of the view coordinate system

    It’s the classic dependency inversion principle which is intentionally done.

  7. added
    feature-request
    VIM
    on Oct 2, 2019
  8. changed the title [-]Allow extensions to determine if a position is within a fold[/-] [+][api] Allow extensions to determine if a position is within a fold[/+] on Nov 6, 2020
  9. costincaraivan commented on Nov 1, 2023

    @costincaraivan
    ContributorAuthor

    Ping 🙂 It's been 4 years, any chance this will end up in a backlog/sprint?

  10. added
    unreleased
    on Feb 28, 2026
  11. added
    insiders-released
    and removed
    unreleased
    on Mar 4, 2026
  12. added
    verification-needed
    and removed on Mar 5, 2026
  13. alexdima commented on Mar 5, 2026

    @alexdima
    Member

    Steps to verify:

    1. Open a file with foldable regions (e.g. a TypeScript file with classes/functions)
    2. Create several folds using Fold (Cmd+Option+[)
    3. Add these keybindings to keybindings.json:
    [
      {
        "key": "ctrl+alt+down",
        "command": "cursorMove",
        "args": { "to": "down", "by": "foldedLine" },
        "when": "editorTextFocus"
      },
      {
        "key": "ctrl+alt+up",
        "command": "cursorMove",
        "args": { "to": "up", "by": "foldedLine" },
        "when": "editorTextFocus"
      },
      {
        "key": "ctrl+alt+shift+down",
        "command": "cursorMove",
        "args": { "to": "down", "by": "foldedLine", "select": true },
        "when": "editorTextFocus"
      },
      {
        "key": "ctrl+alt+shift+up",
        "command": "cursorMove",
        "args": { "to": "up", "by": "foldedLine", "select": true },
        "when": "editorTextFocus"
      }
    ]

    Test Cases

    1. Down skips fold — Cursor above a fold → Ctrl+Alt+Down → lands on first line after the fold
    2. Up skips fold — Cursor below a fold → Ctrl+Alt+Up → lands on line before the fold
    3. Large fold = single step — Fold a large class body → moving across it takes one step
    4. No folds = normal line movement — In an unfolded region, behaves like "by": "line"
    5. Selection — Ctrl+Alt+Shift+Down/Up extends selection while skipping folds
    6. Multi-cursor — Multiple cursors all independently skip folds
    7. Boundary — Fold at EOF/line 1 → cursor stays put (no visible line beyond)
  14. added
    verified
    on Mar 5, 2026
  15. locked and limited conversation to collaborators on Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

VIMapifeature-requestinsiders-releasedverification-neededverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions