microsoft / microsoft/monaco-editor
[Bug] GlyphMarginWidget seems not working correctly in modifiedEditor
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
const originalText = `
function binarySearch(arr, target) {
let left = 0;
let right = arr.length - 1;
while (left <= right) {
let mid = Math.floor((left + right) / 2);
if (arr[mid] === target) {
return mid;
} else if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return -1;
}
`
const modifiedText = `
function search(array, target) {
let left = 0;
let right = array.length - 1;
while (left <= right) {
let mid = Math.floor((left + right) / 2);
if (array[mid] === target) {
return mid;
} else if (array[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return -1;
}
`
function updateGlyphMargin(editor, isPosOriginal, lineNumber) {
var glyphMarginWidget = {
getId: function () {
return isPosOriginal ? 'addCommentIconLeft' : 'addCommentIconRight';
},
getDomNode: function () {
const domNode = document.createElement('div');
domNode.innerHTML = '+';
domNode.dataset.lineNumber = lineNumber.toString();
domNode.title = 'add comment';
return domNode;
},
getPosition: function () {
console.log(lineNumber)
return {
lane: 1,
zIndex: 1,
range: new monaco.Range(lineNumber,1,lineNumber,1)
};
}
};
editor.removeGlyphMarginWidget(glyphMarginWidget);
editor.addGlyphMarginWidget(glyphMarginWidget);
}
// Hover on each property to see its docs!
const newEditor = monaco.editor.createDiffEditor(document.getElementById("container"), {
theme: 'vs-dark',
automaticLayout: true,
readOnly: true
});
newEditor.setModel({
original: monaco.editor.createModel(originalText, 'javascript'),
modified: monaco.editor.createModel(modifiedText, 'javascript')
});
const originalEditor = newEditor.getOriginalEditor();
const modifiedEditor = newEditor.getModifiedEditor();
originalEditor.onMouseMove((e) => {
if (e.target.position?.lineNumber) {
updateGlyphMargin(originalEditor, true, e.target.position.lineNumber)
}
});
modifiedEditor.onMouseMove((e) => {
if (e.target.position?.lineNumber) {
updateGlyphMargin(modifiedEditor, false, e.target.position.lineNumber)
}
});
Reproduction Steps
just apply the code and try to hover on originalEditor and modifiedEditor, only originalEditor show glyphMarginWidget, modifedEditor got nothing.
Actual (Problematic) Behavior
The glyphMarginWidget works well in originalEditor but not working in modifiedEditor. With chrome developer tool, we can see that the glyphMarginWidget always got display: none
Expected Behavior
modifiedEditor should show glyphMarginWidget like originalEditor when hover event trigger.
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 compare the GlyphMarginWidget behavior in originalEditor and modifiedEditor, especially the addGlyphMarginWidget position returned by updateGlyphMargin. Confirm why the modified editor hides the widget, then verify that hovering modified-editor lines displays it like the original editor.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100