How to identify elements in codemirror uniquely

This is related to my gsoc project: improving pdf previewer.

What I want to implement is a way to remember scroll position of the pdf-viewer across note re-renders.

The note previews are created by converting the note content to html and rendering it into an iframe. So everytime a note is updated, the whole process is fired again.

This makes it difficult to identify each pdf links separately to remember it’s scroll positions.

My approach (flawed)

I will be storing the data in localStorage or session storage where I will identify each link as ‘{link-url}+{index}’. Here the index is counted separately for each url, for ex: it will be index 1 (zero based) if there is only another link of same url above it. But from the overall view it might be index 3. (3 links above it where 2 of them are different urls).

This will have an obvious drawback like if we add a same url link above another, the new link will take the original one’s state, which is wrong.

The best way would have been if we could identify each link uniquely maybe a unique id getting assigned to each url link everytime it’s added without the user noticing it.

Any alternatives or suggestions on this?

1 Like

I suppose this is a very uncommon use case. Maybe it's fine to allow incorrect behaviour here?