Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting current caret position #14

Closed
selfrefactor opened this issue Sep 18, 2015 · 1 comment
Closed

Getting current caret position #14

selfrefactor opened this issue Sep 18, 2015 · 1 comment
Labels

Comments

@selfrefactor
Copy link

I couldn't reach the current caret position of the editor, no matter whether I am using Javascript or jQuery for that. Is there a way to get this property?
BTW you have made a great editor and thanks for that.

@anthonyjb
Copy link
Member

Hi @selfrefactor - thanls for the kind comments. To get the current caret position for the focused element you can use the elements selection() method like so:

var focused = ContentEdit.Root.get().focused()
if (focused) {
    console.log(focused.selection());
}

The selection returned will be a ContentSelect.Range instance. To determine the start/end of the selection use:

range.get() // returns an array [start, end]

If that's not working for you or I've not answered your question could you post an example of your code and I'll see if I can help further (might well be you've found a bug).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants