Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Is it possible to convert a Point to a total byte or character offset? #96

Closed
jpsim opened this issue Sep 4, 2015 · 3 comments
Closed
Labels

Comments

@jpsim
Copy link

jpsim commented Sep 4, 2015

I'm building an Atom package and need to calculate the equivalent byte offset from a given Point. How would you recommend I do this?

e.g.

1234
56

For Point(row: 1, column: 2) (point immediately after 6), the equivalent byte offset would be 7.

@lee-dohm
Copy link
Contributor

lee-dohm commented Sep 5, 2015

It looks like TextBuffer.characterIndexForPosition does what you need. I assume that you'll need to supply it a Point in buffer coordinates though. If all you have is screen coordinates, you should be able to convert to buffer coordinates by using TextEditor.bufferPositionForScreenPosition.

@jpsim
Copy link
Author

jpsim commented Sep 5, 2015

Thanks, that's exactly what I needed.

@jpsim jpsim closed this as completed Sep 5, 2015
@lee-dohm
Copy link
Contributor

lee-dohm commented Sep 5, 2015

You're welcome 😀

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

No branches or pull requests

2 participants