How to prevent widgets from being deleted by codemirror virtual list rendering mechanism

I implemented a widget component on a certain line of code. When scrolling, I will change this widget to a floating style. However, I found that after scrolling to a certain distance, the rendering mechanism of the virtual list deleted my widget html element. Is there any way to avoid this situation?

No, not for content or widgets rendered in the content. Only the things within the viewport will be rendered. You could move the widget (or a copy of it) out of the content and into an overlay (for example an absolutely positioned element appended to EditorView.dom).

Thanks for your reply
I tried setting the widget’s position to absolute, but it was still deleted from the virtual list.
My requirement is to set the widget to sticky display when the widget is not in the viewport.
Also, I noticed that the selected line or active line DOM will not be deleted, so I want to know if there is any state to control this.

No, you cannot control the viewport. Position styling won’t change how widgets are handling. Hence my suggestion to make your element a child of the outer DOM, not part of the document.

OK, got it.