MarkdownView.setEphemeralState highlights a wrong line if the note has a footnote

Hi, I’m trying to write a function that scrolls the reading view to the specified line and highlights it.

Let’s assume that the current view is already set to reading view.

I know that I can use the view.setEphemeralState method (which calls view.previewMode.renderer.applyScrollDelayed internally) to do this.

Example where it works

For example, if I have the following document:

Hello, world [^1].

[^1]: This is a footnote.

This is the line that I want to focus on.

Some text after the line.

then, executing the following while focusing on the markdown view produces the desired result. (again, we are assuming that we are opening reading view)

// "4" is the 0-based line number of the line that I want to focus on
app.workspace.activeEditor.setEphemeralState({line: 4})

Result:

Example where it doesn’t work

However, if I remove the last lines so that:

Hello, world [^1].

[^1]: This is a footnote.

This is the line that I want to focus on.

then, the exact same command will result in something like this:

As you see, it focuses on the foot note instead of the target line.

Question

Does anyone know how I can reliably focus on and highlight the desired line? Thanks!

Addiotional information

The same thing also happens when triggering hover popover (page preview):

// "Note" is the name of the note above
app.workspace.trigger("link-hover", { hoverParent: null }, document.body, "Note", "", { scroll: 4 })

(notice the state parameter { scroll: 4 })

Update

This might be a bug. See the following thread for the details: