diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-01-06 11:20:49 -0800 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-01-06 11:20:49 -0800 |
| commit | 73c2fbc538a34f89391ac5174357aac9af253672 (patch) | |
| tree | b9ade6c5f7f02d4c8c38b6961580547e91d446f0 /src | |
| parent | Use more idiomatic error handling. (diff) | |
| download | editor-73c2fbc538a34f89391ac5174357aac9af253672.tar.zst | |
Wrap the cursor around at the ends of a line.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 17 |
1 files changed, 12 insertions, 5 deletions
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<dyn Error>> { 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(); } |
