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.
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.