getModelMarker() doesn't include newly introduced Markers
See original GitHub issueDescribe the bug
Using getModelMarkers()
when handling the onChange
event of ControlledEditor
does not include any ModelMarkers that were introduced by the change being handled.
It does, however, include any ModelMarkers that existed before the current change.
const handleEditorChanged = (ev, value) => {
const errors = monacoRef.current.editor.getModelMarkers();
console.log(errors);
// returns [] when first ModelMarker is introduced
};
To Reproduce https://codesandbox.io/s/nifty-ardinghelli-7w84o
Expected behavior
When called inside the ControlledEditor’s onChange
handler, getModelMarkers()
should include any ModelMarkers that were introduced by the change being handled.
Desktop (please complete the following information):
- OS: MacOS
- Browser: Chrome
Additional context
I would also think this is possible without using the monaco
instance, since I already have a ref for the editor
itself (see codesandbox)… Please let me know if I’m just going about this all wrong 🙂
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
I examined the case; I reckon it won’t be “fixed”. I mean we call
onacoRef.current.editor.getModelMarkers()
right after content is changed, butmonaco
to understand are there any problems “need” time. The example @SakaSaiTrinath mentioned, works. I create a snippet based on that. There is also another method. Currently, I am planning a new major version release, and probably one of them I’ll use to provide something likeonValidate
, but for now you can use one of the versions mentioned above.monacoRef.current.editor.getModelMarkers()
function returns the current markers but not the updated markers. So, you can’t use this function to track errors.Instead this works well.