diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-01-06 12:11:43 -0800 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-01-06 12:11:43 -0800 |
| commit | befdde33f29ab435b328c3bc501562e2e9386a8e (patch) | |
| tree | f3e038d65d095d37350ca877c21292e5388cb8c5 /src/rope.rs | |
| parent | Wrap the cursor around at the ends of a line. (diff) | |
| download | editor-befdde33f29ab435b328c3bc501562e2e9386a8e.tar.zst | |
Truncate long lines.
Diffstat (limited to 'src/rope.rs')
| -rw-r--r-- | src/rope.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/rope.rs b/src/rope.rs index c5e9aa1..5f4fca8 100644 --- a/src/rope.rs +++ b/src/rope.rs @@ -278,4 +278,21 @@ impl Rope { } return self.len(); } + + pub fn char(&self, index: usize) -> usize { + if index == 0 { + return 0; + } + let mut count = 1; + for i in 1..self.len() { + if !self.is_char_boundary(i) { + continue; + } + if count == index { + return i; + } + count += 1; + } + return self.len(); + } } |
