microsoft / microsoft/monaco-editor

[Bug] DiffEditor folding not working properly after setting new model

Open
#4,903 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

https://microsoft.github.io/monaco-editor/playground.html?source=v0.52.2#XQAAAAKoCgAAAAAAAABBqQkHQ5NjdU_A3v_fvV7aSEHtA0Rvtgnl-tR47YVb6__LUAu4rUHJIRdn1oa9jNB9v2vq4CUrhXrWjtMMM8X0C7Z_YtNjG6APzg1S-UugxEewoi7qbHucAZkjd3ATahfN5E6U2gvZ2pblJ6ztRAw-e76euqBZDWQfSisulxuR9nmgYLjWZIOTdWPQxIW8e3fdW_GGJcwCZa2yNj4ZroqBDYfUn3JtmbMr-i9b8ebtXOTvWj8-vb-mi5NFtmrwimi8ViNZZQ4w3HGCFfT2gwlSMVi54FbgkkZdOY-IminkQ2qq-eAJWT1dHmtnuhc1PC28MpIctp5hHHisrQl8H8ezXcMTfTEINk5JXV20y1Iva8ICgZP78jrlIJUkAuHD_gJur8JlBZiYn2kF7loZfc4g6OzSo32_A-KIp_3MQP8wkcHwjiiJGmBi7Mkik9ESUIxCEUst93_4uxpW0z8tEnV9_mOrcxJ_K-ZlIKujZ2ZH3WtkvAnQ8p1yy33ZPC0mj1qKIVYdJjB1jo0sdN4ZjyaJWe7lMyv3xY6MSltyryAcTULKoJ7_0ghWqizlaxMavj6msrXCSYfi1zh00SlYvBdUrMIWo2QyntagkC_1RHV-gO0eQracjyR9KIwmDawKdtoY09rfA5W53heFVFqYLI9d6WeAkmsJ2K5hCCW-qLVsL0UQaNFQ6vaXH_JGrU68MRLqftxNzE1g_o1i0E6SJ-61fGwMhzrvFj14yRuAJNeGZJfk-8rwY1SkE3udYsZvYWZUyWws4pj_XuFM4B-nWq47RVvKOFG-7xMpdbdfeP_DN6EO

Monaco Editor Playground Code
var originalModelText = "This line is removed on the right.\njust some text\nabcd\nefgh\nSome more textjust some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left."
var modifiedModelText = "just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left.just some text\nabcz\nzzzzefgh\nSome more text.\nThis line is removed on the left. and another diff something"

var originalModel = monaco.editor.createModel(
	originalModelText,
	"text/plain"
);
var modifiedModel = monaco.editor.createModel(
	modifiedModelText,
	"text/plain"
);

var diffEditor = monaco.editor.createDiffEditor(
	document.getElementById("container"),
	{
		// You can optionally disable the resizing
		enableSplitViewResizing: false,
		readOnly: true,
      	hideUnchangedRegions: { enabled: true },
	}
);
diffEditor.setModel({
	original: originalModel,
	modified: modifiedModel,
});



window.viewMode = () => {
	diffEditor.getModifiedEditor().getModel().setValue(modifiedModelText + 'asd');
	diffEditor.updateOptions({
      readOnly: true,
      hideUnchangedRegions: { enabled: true },
    });
	diffEditor.trigger('fold', 'editor.foldAll') 
}

window.editMode = () => {
	diffEditor.getModifiedEditor().getModel().setValue(modifiedModelText);
	diffEditor.updateOptions({
      readOnly: false,
      hideUnchangedRegions: { enabled: false },
    });
	diffEditor.trigger('unfold', 'editor.unfoldAll') 
}
Reproduction Steps
  1. Click EditMode button to unfold and add some text
  2. Click ViewMode button to return to readonly state and fold code
  3. Unchanged code didnt collapse
Actual (Problematic) Behavior

Looks like after setting new model folding feature is not working properly and doesnt collapse unchanged code. (Buttons for expanding/collapsing folding are working)

Expected Behavior

After changing model, turning on folding again should fold and collapse not changed code

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 with the linked Monaco Editor Playground reproduction and trace the DiffEditor model update, option changes, and fold/unfold commands in the editMode and viewMode sequence. Confirm the unchanged-region folding behavior after the model text changes; done means returning to view mode collapses unchanged code as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.