MTilsted
MTilsted

Reputation: 5518

Scroll to marker in ckeditor 5

Is there a method to scroll the view to a marker?

I just need a method to ensure that my marker is visible to the user.

I did find the method scrollViewportToShowTarget (@ckeditor/ckeditor5-utils/src/dom/scroll) but I was unable to get it to work. I tried to use

scrollViewportToShowTarget( {
  target: marker.getRange(),
  viewportOffset: 20
} );

But that just gave me a TypeError: "elementOrRange.ownerDocument is undefined"

Upvotes: 1

Views: 1035

Answers (1)

Reinmar
Reinmar

Reputation: 22023

scrollViewportToShowTarget() accepts a DOM range as a param. You passed CKE5's model range there.

You need to use Mapper#toViewRange( modelRange ) to get the view range for your model range. And then DomConverter#viewRangeToDom( viewRange ) to finally get the DOM range.

Upvotes: 3

Related Questions