aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 2b6a814..0dfe335 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,6 +20,25 @@ fn line_offset(
line: &Rope,
col: u16,
) -> Result<usize, Box<dyn Error>> {
+ let mut n = 0;
+ for i in 0.. {
+ if i == line.len() {
+ return Ok(i);
+ }
+ let c = line.byte(i);
+ if c > 127 {
+ break;
+ }
+ if n == col {
+ return Ok(i);
+ }
+ if c == b'\t' {
+ n += 8 - n % 8;
+ } else {
+ n += 1;
+ }
+ }
+
// Binary search :D
let mut lo = 0;
let mut hi = line.len() + 1;