Reputation: 3545
I have a requirement to show java code in the monaco editor, what I need to do:
I searched online and knows how to highlight the words using editor.deltaDecorations, but I really have no idea how to add event handler to those highlighted words.
Also we are now using ngx-monaco-editor, an angular wrapper for monaco, any solution to provide highlights and click handling for this component?
Thanks for your suggestions.
Upvotes: 2
Views: 1371
Reputation: 53337
You cannot attach a mouse handler to the highlighted words, but you can do so for the editor itself.
A possible approach would be to attach handlers to onMouseDown and onMouseUp. When the mouse-down event arrives use getWordAtPosition and check if that is one of special words. If so, store it somewhere. In mouseUp do the same and compare the stored word with what you found in the up event. If they are the same do your actual click handling.
Upvotes: 3