Comments (1)
Depends on how you define the column number. If you define it as the utf-8 offset from the start of the line:
let col = byte - rope.line_to_byte(rope.byte_to_line(byte))
If you define it as the utf-16 offset from the start of the line:
let line = doc.byte_to_line(byte);
let line_start = doc.char_to_utf16_cu(doc.line_to_char(line));
let col = doc.char_to_utf16_cu(doc.byte_to_char(byte)) - line_start;
If you define it as the utf-32 offset from the start of the line:
let line = doc.byte_to_line(byte);
let line_start = doc.line_to_char(line);
let col = doc.byte_to_char(byte) - line_start;
If you define it as the actual visual column (for example for vertical movement in the editor) that will depend on how you render the text and will likely require some form of grapheme segmentation and using something like the unicode-width
crate. The first three options are already possible with the current API. The last option is not uniformly defined and out of scope (but also possible with the current API by using the chunks iterator, its just more work)
from ropey.
Related Issues (20)
- Incoming breakage due to static assert on size HOT 6
- Insert to another rope HOT 4
- Performance issue with the redundancy operations HOT 1
- `ropey` doesn't agree with `wc` HOT 7
- Async IO support for `Rope`? HOT 1
- Chunks iterator get's confused when you change direction twice. HOT 5
- test case failed lines_exact_size_iter_04 HOT 1
- attempt to compute `0_usize - 1_usize`, which would overflow HOT 2
- RopeBuilder's Default derive creates an invalid RopeBuilder HOT 1
- `TextInfo` in `Chunks` API HOT 11
- subtract with overflow in new line iterator HOT 4
- Comparaison with Xi editor HOT 1
- Is it okay if I publish a fork of this crate that works with any type of data? HOT 3
- peek methods on iterators. HOT 3
- Lines iterated ropey is ~2x slower when highlighting ~1k lines of code than a simple Vec of Vec of chars HOT 1
- Rope Graphemes Example HOT 1
- Tests and `debug_assert!` HOT 2
- Test `pt_shrink_to_fit_01` fails on i686 HOT 14
- Chars::reversed not working as expected HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ropey.