aboutsummaryrefslogtreecommitdiffstats
path: root/src/rope.rs
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2024-01-06 12:11:43 -0800
committerRose Hogenson <rosehogenson@posteo.net>2024-01-06 12:11:43 -0800
commitbefdde33f29ab435b328c3bc501562e2e9386a8e (patch)
treef3e038d65d095d37350ca877c21292e5388cb8c5 /src/rope.rs
parentWrap the cursor around at the ends of a line. (diff)
downloadeditor-befdde33f29ab435b328c3bc501562e2e9386a8e.tar.zst
Truncate long lines.
Diffstat (limited to 'src/rope.rs')
-rw-r--r--src/rope.rs17
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();
+ }
}