diff options
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; |