microsoft / microsoft/monaco-editor

[Bug] GlyphMarginWidget seems not working correctly in modifiedEditor

Open
#4,331 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.45.0#XQAAAAL_CAAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscxFFkJ8Zmn-4FNw7EJFXgGEG8BcQ_Fjg3kpvZbppnCzrIpn59Pt_K7bHHUFAytminI-rT7FODkiWGR_GOJXp0qJBskL81HIRliV0AzzE2LjzEUOKfuVt0Dyn-SzlP6OeT-5ewKRDQGED3pQ3mkKir1Hcogm6hwWgQb8-XQY5l16M7bbhfJeHTCoQT3jGerAeYadW2sBYxICpWaHCbFS7DQmeSJ0ZubV7tfq2qaiT2RsG9yjgG8x5lPRIEpz9k7e5oc-qQamNKk_k8YL2NoLG91XWO0qHf0fZPECLgCSBOI4jIN-qrqlbEgdyMWImzh1hpiLEEl0Po0-MxF44j3hb4NsRcC6h04KFVRBioNQkHN0dc91olhx4S2Uvy5FCYbaRESkp8nLzPTrIRnkzoQw231lmuvdAISJfQsE9cbdSQkclkKxEcfy92MCFVqg9SeVQInLT6PTul1-vTZq5vg04yL6FtJa2OEMWiPRXdRwvwOnrFqihZhB3soJuMn_7S1533ZdWqJg-0olxB9DrAUC21ZohHwc3T03Fc5ae7ece0ZxIokZ0tFF2-bvwdgCpCLQwb3OeDhfE8YLjifnyGDB__Kj2db5nDP2GShvWl5797MH_yUTElHhrnlxYkLRn6xQp6bKLEl0l9kwN9dWxVgE8ZvzqmuwQg14ibJpCPHLIOR6_lzdaPbgf3HwbWh39K8fF5my33szUL276GSYVRytTiZFyPbloAqsp4AI8HqjYPdPb-7synKzGTIkKzdieVXX4gZEXa1Ao3xSYKxXal8p0Vi1M1Q44nA9DgL70UdwcakdAUnWmvCRyQghf5h-pdNwdmjDoaFMsp_IsduJOehNHLMAgKWC1vuxpN0ES_l1Ba5fpGwUkt9nAM2t8XpUe7exh9YITgK_6NZEtLPeGRArwKkHiw6uwFCSwzWqkeSEiFdIFKUzDbzSh1vexQGpaf496nnpRkFCtuR8HYSnXIbELyoR4sEaLXrAa0xoyIZ-SW66LWe-vkDU6kzOsqvIVSVKFvSSIk5FPrZRp5NQ9VmII2Bq0Nh0Q1euiM7r5uWV_hqRURN_2GJDWHCNqJeZ5aL7rzRi4JMwhNm-b3_-wN5Zg

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

image

Expected Behavior

modifiedEditor should show glyphMarginWidget like originalEditor when hover event trigger.

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.