microsoft / microsoft/monaco-editor
View Zones move to wrong position
@alexdima is already working on this.
Since Sep 8, 2020.
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 4.1k
- Avg merge
- 17h 58m
- Merged PRs (30d)
- 1
Description
monaco-editor version: 0.20.0
Browser: Firefox, Chromium
OS: Linux
Playground code that reproduces the issue:
let ed = monaco.editor.create(document.getElementById("container"), {
value: "1. Insert more lines here by pressing enter:\n\nZone should always be below this line.\n\n\n2. Delete most of this line to trigger ViewZones._recomputeWhitespaceProps()",
wordWrap: "wordWrapColumn",
wordWrapColumn: 40
});
ed.changeViewZones((vzChanger)=>{
let domNode = document.createElement("div")
domNode.style.background = "#ff0000"
vzChanger.addZone({
afterLineNumber:3,
heightInLines: 1,
domNode
})
})
Any time a view zone is moved to a different absolute line number by text flow, and then something happens anywhere in the document that triggers ViewZones._recomputeWhitespaceProps(), the view zone winds up in the wrong place.
You can also get this to happen in VS Code in a somewhat convoluted way:
- Open a typescript file
- Make an error that gets you a red squiggle
- Press F8, or mouse over the red squiggle and click "Peek Problem", to get a view zone/overlay widget combination displaying the error message
- Insert or remove one or more lines above the error. The zone flows with the text as expected.
- Toggle word wrap with Alt-Z, or fold or unfold something anywhere in the file, or (if word wrap is on) change the height of a word wrapped line anywhere in the document
- Now the error is displayed in the wrong place (at its original absolute line number)
The problem seems to be that ViewZones._recomputeWhitespaceProps() calls ViewZones._computeWhitespaceProps() which looks at IViewZone.afterLineNumber and expects it to be up to date. This is a reasonable assumption for the other callers of _computeWhitespaceProps, which are only called when adding or changing the layout of a zone, when the creator of the ViewZone is specifying a point in the file to insert the zone. But it is not reasonable at an arbitrary time later, when text flow may have moved the ViewZone to a different absolute line number but there is no obvious way to update afterLineNumber accordingly.
I assume that _recomputeWhitespaceProps() exists for a reason, but when I stub it out with "return false" it seems to solve this problem. I can't propose a specific fix without better understanding what the function is trying to do.
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.
Assessment
This issue has not been assessed yet.