From 08eb793fcecb70c02c83ff5fdc9407c0fadd113c Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Fri, 27 Mar 2026 05:03:28 -0700 Subject: 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 --- src/main.rs | 17 ++++++++++++++--- 1 file 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?; -- cgit 1.4.1