Cursor position gets reset after updating Editor content

6 posts, 0 answers
  1. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 19 Oct 2015 Link to this post

    My use case involves the user editing the content of the editor while the server occasionally updates some of the values in the text

    However, when the server sends an update and the editor.value("string") happens, the cursor position is reset to the start of the text, instead of leaving it where it is

    I've tried fiddling with selected ranges and such but it doesn't seem to be working

  2. Dimo
    Admin
    Dimo avatar
    8331 posts

    Posted 21 Oct 2015 Link to this post

    Hello Matt,

    Indeed, the cursor position is not persisted after value update, because there is no universal and reliable way to detect where the old position was and if the same content still exists. I am afraid that the desired behavior is not supported out-of-the-box, but you may be able to implement some custom solution, if the value changes follow a certain pattern.

    Here is a demo that you can use for reference.

    http://docs.telerik.com/kendo-ui/web/editor/how-to/set-caret-position-using-javascript

    You will also need ranges and selections.

    http://docs.telerik.com/kendo-ui/api/javascript/ui/editor#methods-getRange
     
    http://docs.telerik.com/kendo-ui/api/javascript/ui/editor#methods-getSelection
     
    https://developer.mozilla.org/en-US/docs/Web/API/Range
     
    https://developer.mozilla.org/en-US/docs/Web/API/Selection

    Regards,
    Dimo
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 04 Nov 2015 in reply to Dimo Link to this post

    For others information, the demo doesn't work ​for most content since it relies on body.firstChild, which will always be the first paragraph in an editor.
  5. Dimo
    Admin
    Dimo avatar
    8331 posts

    Posted 05 Nov 2015 Link to this post

    Hello Matt,

    The idea of the example is to provide a starting point and hints about the required logic and approach. Each specific case should be handled with a specific implementation, based on the editable content's DOM structure and Range APIs.

    Regards,
    Dimo
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2012

    Posted 12 Nov 2015 in reply to Dimo Link to this post

    Sure, but the demo description says "how to set the position of the caret inside a Kendo UI inline Editor by using JavaScript".

    It doesn't mention that it won't work for editors with line breaks, which I would say is most editors (otherwise you'd use a textbox?)
  7. Dimo
    Admin
    Dimo avatar
    8331 posts

    Posted 17 Nov 2015 Link to this post

    Hi Matt,

    We updated the documentation page to include a scenario with multiple paragraphs. Changes will take effect shortly, as soon as the new version is uploaded.

    Regards,
    Dimo
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready