diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-03-27 16:59:00 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-03-27 16:59:00 -0700 |
| commit | a80f9a1b97e1be194cb91a3b78717b0824d3bce8 (patch) | |
| tree | a7481653125ce36b7d15a80ee763e87642ae053b /src/main.rs | |
| parent | 8d0a78e708dd46aec40d3a06459c86d9c10f1e3b (diff) | |
fully implement the first-nonblank-column thing for H and L
surprisingly intricate, but although it looks messy now, this approach will clean up nicely Force-Push: yes Change-Id: Ic9c90982787a58110ec0a189844742a1e6c2216f
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index 4b5dc5a..70bc0b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use crate::types::*; use smol::prelude::*; use smol::fs::File; +use smol::io::Cursor; use smol::lock::RwLock; use std::path::PathBuf; use std::process::ExitCode; @@ -464,12 +465,31 @@ impl Ivy { async fn first_non_blank_column(&mut self) -> Result<()> { let row = *self.window.read().await.cursor_row.read().await; + let buffer = self.buffer.write().await; + + if let Some(row_span) = buffer.line_span(row).await { + let mut offset = 0; + loop { + let sub_span = row_span.start + offset .. row_span.end; + let mut contents = buffer.contents.write().await; + let mut cursor = Cursor::new(&mut contents[sub_span]); + + if let Ok(decode) = encoding::read_utf8_char(&mut cursor).await { + offset += decode.skipped_bytes; + + if decode.c.is_whitespace() { + offset += decode.found_bytes; + } else { + break; + } + } else { + break; + } + } - if let Some(span) = self.buffer.read().await.line_span(row).await { - /* TODO */ let window = self.window.write().await; - *window.cursor_column.write().await = 0; - *window.cursor_neutral_column.write().await = 0; + *window.cursor_column.write().await = offset; + *window.cursor_neutral_column.write().await = offset; } else { let window = self.window.write().await; *window.cursor_column.write().await = 0; |