monaco-editor

monaco editor dynamic set viewzone's height


I used monaco editor's OverlayWidget and Viewzone api to insert a inline text in monaco editor like the monaco editor example https://microsoft.github.io/monaco-editor/playground.html#interacting-with-the-editor-listening-to-mouse-events.

but when I changed the OverlayWidget's height, the Viewzone's height was not changed.

I tried use layoutZone api to reset viewzone's height, but It seemed not work.

editor.changeViewZones((accessor => {
       accessor.layoutZone(viewZoneId);
       this.doLayout(host, layoutInfo);
}))

So what is the correct way to dynamic set viewzone's height?

Thanks!


Solution

  • I solved this problem。

    yes, accessor.layoutZone(viewZoneId); will reRender the viewzone.

    the key is use a getter method of viewzone's heightInPx property like below;

    const viewZone = {
        afterLineNumber: lineNumber,
        get heightInPx() {
            return host.offsetHeight;
        },
        domNode,
        onDomNodeTop: (top) => {
            host.style.top = top + "px";
        },
    };