Scroll editor to cursor

1 Answer 204 Views
BottomNavigation Editor
Franco
Top achievements
Rank 1
Franco asked on 02 Sep 2021, 09:37 PM

Hi! I wanted to know how to programmatically scroll the editor to the current cursor. I am currently using


this.kendoEditor.exec('insertText', { text: '##FLAG##' });
this.kendoEditor.value = this.kendoEditor.value.replace('##FLAG##', '<b>content</b>');

and if the cursor was at the bottom the user will not see the new text.

1 Answer, 1 is accepted

Sort by
0
Martin Bechev
Telerik team
answered on 07 Sep 2021, 02:54 PM

Hello Franco,

Thank you for the provided code snippet.

Indeed there is no built-in mechanism to scroll the Editor content to the desired position.

What can be done is to insert a custom element with an id attribute, and then to call scrollIntoView method of that element, like so:

 insertText(editor: EditorComponent) {
    editor.exec('insertText', { text: '#CURSOR#' });
    editor.value = editor.value.replace(
      /#CURSOR#/,
      "<b><span id='my-content'>content</span></b>"
    );

    const iframeDoc = (document.querySelector('.k-iframe') as HTMLIFrameElement)
      .contentDocument;

    const customSpan = iframeDoc.getElementById('my-content');
    customSpan.scrollIntoView();
  }

Here is an example:

https://stackblitz.com/edit/angular-7j9fpr

Please bear in mind that the suggested approach is just a workaround and it is not supported by the component itself. The developer can further extend the logic or implemented an entirely new one based on the project requirements.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
BottomNavigation Editor
Asked by
Franco
Top achievements
Rank 1
Answers by
Martin Bechev
Telerik team
Share this question
or