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

No way to set cursor position specified in characters #378

Closed
ghost opened this issue Aug 14, 2011 · 5 comments
Closed

No way to set cursor position specified in characters #378

ghost opened this issue Aug 14, 2011 · 5 comments

Comments

@ghost
Copy link

ghost commented Aug 14, 2011

There doesn't appear to be any way of setting the cursor position from the start of the text being edited. This is possible with a plain textarea but is only possible by calculating the row and column and using moveCursorTo in Ace.

Example: say I have a 100 char long string scattered with newlines and want to move to the 50th char, this can't be done easily with the current implementation. Maybe a moveCursorToIndex method? ...am I missing something obvious?

@fjakobs
Copy link
Contributor

fjakobs commented Aug 17, 2011

Unlike textarea which is character based, Ace is completely line based. This makes indexing by character a rather expensive operation. At this point I have no intention to add something like a moveCursorToIndex or convertIndexToPosition method.

It should be easy to be implemented by the user, which also make him aware of the computational costs involved.

@fjakobs fjakobs closed this as completed Aug 17, 2011
@ghost
Copy link
Author

ghost commented Aug 17, 2011

Thanks for the answer

@pvdz
Copy link

pvdz commented Oct 13, 2012

Fwiw, I'm banging my head against the wall right now because these api's are missing. It might make sense to not expose them from the editor pov, but certain operations really do work with the text in a serial way.

Maybe it's a good idea to expose these methods in a plugin? Gives you an extra chance to warn that the computation is pretty expensive, but that if you still want it, the plugin can do it for you.

We've managed to get to it now, but with the arcane way we went about it, I'm still unsure whether it's "the right way" (tm).

@nightwing
Copy link
Member

The problem is that there is no "the right way" (tm).
and which method to use depends on how fast you need it to be.
would it help if we add function you've used somewhere in the documentation?

@pvdz
Copy link

pvdz commented Oct 15, 2012

If nothing else, then yeah. I'm sure somebody will be happy to find examples on how to translate index2pos and pos2index.

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

No branches or pull requests

3 participants