microsoft / microsoft/monaco-editor

[Bug] editor.foldLevel1 does not fold first region if it's the first line

Open
#4,907 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

Here the first region does not collapse:

https://microsoft.github.io/monaco-editor/playground.html?source=v0.52.2#XQAAAAKAAQAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscwzkH1E3g-pPU-gOIt1aALZLEqkt_AsDUtxBoQv5uI2hCz9f2-jXVC9fP-GAjuKEjJtSU2GXaJsaDr4hOsG9JYoqf2WWwnp0_fVd0F5Wu5iaQiw7aveh3FGJ7N47AP0wXMBB2oiHrZofp173ttdAqyHKPQZ6B-Sfni8OS_YBUShaqfsZi_uzKlo77MwiXO3sbBnULAMs83K-rmXfTCSLtXAO6I8C-1tULJYa67D44eQaDKFAkpUfJXeyOeVmBwI4gUiVFGCVwa1tL19HAGFOW6F8L_8Ny2IA

Adding a non-folding region beforehand (like a newline) fixes this:

https://microsoft.github.io/monaco-editor/playground.html?source=v0.52.2#XQAAAAJ5AQAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscwzhm7M3g-pPU-gOIt1aALZLEqkt_AsDUtxBoQv5uI2hCz9f2-jXVC9fP-GAjuKEjJtSU2GXaJsaDr4hOsG9JYKdgiy6gISMxFMX_IUt6WXKqvpCBaGP2xuAE5ELWqZxELAGPb3kqP_nCHeMih0Ttz33cqVL5wxLbVddzb8iISI7lNW9E1_8SrRwqcODuJ5MVn5m-L3qfuwQUtWPn4JAKMxtEL48hABSyi7_e9rCCEu_vHKSzx2pXwQLJgW8u325FY2grXzvH-8wHDOg

Monaco Editor Playground Code
var editor = monaco.editor.create(document.getElementById("container"), {
	value: `const hello = () => {
    // This does not collapse
	console.log("hello world");
}
const world = () => {
    // This collapses
	console.log("world, hello");
}`,
	language: "javascript"
});

editor.getAction('editor.foldLevel1').run();
Reproduction Steps

View the sandbox, all level 1 regions should be folded automatically.

Actual (Problematic) Behavior

All regions are folded apart from the first one if that region is on the first line

Expected Behavior

No response

Additional Context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the Monaco Editor Playground reproduction from the linked v0.52.2 examples and inspect the editor.foldLevel1 action with the provided JavaScript sample. Confirm the first level-1 region is skipped while later regions fold, then verify that the corrected behavior folds every level-1 region, including one beginning on the first line.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.