From 73c2fbc538a34f89391ac5174357aac9af253672 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sat, 6 Jan 2024 11:20:49 -0800 Subject: Wrap the cursor around at the ends of a line. --- src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index a427d27..7f2beaa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,17 +141,24 @@ fn edit(file: &OsStr) -> Result<(), Box> { Key::Left => { state.cursor_col = std::cmp::min(state.cursor_col, state.line_cols); if state.cursor_col == 0 { - continue; + state.cursor_row -= 1; + let _ = state.repaint_line_full(); + state.cursor_col = state.line_cols; + state.line_offset = state.buf.line(state.cursor_row).len(); + let _ = write!(stdout(), "\x1b[{}G", state.cursor_col+1); + } else { + state.cursor_col -= 1; + let _ = state.repaint_line_full(); } - state.cursor_col -= 1; - let _ = state.repaint_line_full(); let _ = stdout().flush(); } Key::Right => { if state.cursor_col >= state.line_cols { - continue; + state.cursor_row += 1; + state.cursor_col = 0; + } else { + state.cursor_col += 1; } - state.cursor_col += 1; let _ = state.repaint_line_full(); let _ = stdout().flush(); } -- cgit v1.3.1