From a80f9a1b97e1be194cb91a3b78717b0824d3bce8 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Fri, 27 Mar 2026 16:59:00 -0700 Subject: 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 --- src/main.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/main.rs') 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; -- cgit 1.4.1