Is it possible to inject javascript event listeners to HoverProvider?


Is there a way to inject event listener or custom code to Monaco Hover Provider contents when registerHoverProvider function is called?

    monaco.languages.registerHoverProvider('javascript', {
      provideHover: function (model, position) {
        return {
          range: new monaco.Range(1, 1, model.getLineCount(), model.getLineMaxColumn(model.getLineCount())),
          contents: [
            {
              isTrusted: true,
              supportHtml: true,
              // Use markdown or HTML to create a link and when 
              // that link is pressed, custom javascript code will be executed
              // with something like onclick="..."
              value: '<a onclick="code_here"> click me </a>'
            }
          ]
        }
      }
    })

Here’s the official example of hover events: https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-hover-provider-example

Source: JavaSript – Stack Overflow

November 3, 2021
Category : News
Tags: javascript | monaco-editor

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.