summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-03-27 05:03:28 -0700
committerIrene Knapp <ireneista@irenes.space>2026-03-27 05:03:28 -0700
commit08eb793fcecb70c02c83ff5fdc9407c0fadd113c (patch)
tree60fdf8bc9c2f98daa0f0062f3f03309b701e5118
parent7b2d4b4724cb9458ceed8d88ed58a4bfe0ea4092 (diff)
hjkl movement is now capped to the dimensions of the buffer... sort of
it only checks in the direction of movement, which means it's possible to get outside the text by going up or down off a longer line, onto a shorter one

also, non-printing characters are passed through raw and treated as being exactly one cell wide, and both those things will need to change at some point (try editing a file with color codes in it)

Force-Push: yes
Change-Id: Ie3e82b45a0dba3e52c06c775652d95335242c39b
-rw-r--r--src/main.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index ea151c8..7f84646 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -185,10 +185,13 @@ impl Ivy {
 
         'j' => {
           self.handle_movement(async |ivy: &mut Ivy| {
+            let buffer = ivy.buffer.read().await;
             let window = ivy.window.write().await;
 
             let mut row = window.cursor_row.write().await;
-            *row += 1;
+            if *row + 1 < buffer.lines.read().await.len() {
+              *row += 1;
+            };
 
             Ok(())
           }).await?;
@@ -209,10 +212,18 @@ impl Ivy {
 
         'l' => {
           self.handle_movement(async |ivy: &mut Ivy| {
+            let buffer = ivy.buffer.read().await;
             let window = ivy.window.write().await;
 
-            let mut column = window.cursor_column.write().await;
-            *column += 1;
+            let row = *window.cursor_row.read().await;
+            if let Some(span) = buffer.line_span(row).await {
+              let width = span.end - span.start;
+
+              let mut column = window.cursor_column.write().await;
+              if *column + 1 < width {
+                *column += 1;
+              }
+            }
 
             Ok(())
           }).await?;