How to know when content rendering is complete

I want to implement a way to restore the scrollbar position when opening the last file。

I wrote a plugin that when destory records the scroll position of the current file. When I open the file again the scroll position is restored。

When I don’t add setTimeout, scrollTop seems to execute as soon as the content is not rendered. When I added setTimeout for a few seconds (when content rendering is done) it achieves what I want

May I ask how to execute the scrollTop operation when the content rendering is completed?

It’s best to, instead of recording pixel positions, find a position inside the viewport + its offset from the top with elementAtHeight, and then use scrollIntoView after creating the editor to put that position back at that offset. The reason is that, even if you scroll after the initial measure, if the document is bigger than the viewport pixel positions of individual lines might be different because out-of-viewport content isn’t precisely measured until it gets into the viewport.

Thanks, what you said is quite reasonable。

Hi, marijn, I did what you said And for reference, the visual area displays the question article

The following is my code implementation:
Get the starting line number of the viewable area,and set it during initialization

question,Scroll up one line each time the file is reopened。
The first time 23, the second time 22, the third time 21… 。 It seems that my blockInfo is calculated incorrectly, how should I calculate this blockInfo?

This may be caused by the fact that you’re scrolling to a specific position, but don’t record its pixel offset, so it’ll ‘snap’ to a line. You can use the yMargin option to scroll to a given offset above a line.