
iCognition
Top achievements
Rank 1
Iron
iCognition
asked on 19 Oct 2015, 05:28 AM
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
5 Answers, 1 is accepted
0
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
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
0

iCognition
Top achievements
Rank 1
Iron
answered on 05 Nov 2015, 12:20 AM
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.
0
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
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
0

iCognition
Top achievements
Rank 1
Iron
answered on 12 Nov 2015, 11:15 PM
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?)
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?)
0
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
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