microsoft / microsoft/monaco-editor
[Bug] DiffEditor folding not working properly after setting new model
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?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Link
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
- Click EditMode button to unfold and add some text
- Click ViewMode button to return to readonly state and fold code
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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