diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-01-11 17:03:07 -0800 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-01-11 17:03:07 -0800 |
| commit | 03bc0d13fa7f1809521b70843ffd50e327a77fdf (patch) | |
| tree | 49193ea9543ae43fc47fa78f79fb1602cffdb20d /src | |
| parent | db087d43659f0760a02d6c32dc7dc0baf2f914f0 (diff) | |
| download | editor-03bc0d13fa7f1809521b70843ffd50e327a77fdf.tar.zst | |
Fix the cursor behavior at line endings.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index 7c672e4..2b6a814 100644 --- a/src/main.rs +++ b/src/main.rs @@ -133,16 +133,18 @@ impl State { let line = self.line(); write!(stdout(), "\x1b[{}H\x1b[K", self.cursor_row + 1)?; line.slice(0, self.line_offset).print(&mut stdout())?; - if self.line_offset == line.len() { - write!(stdout(), "\x1b[C\x1b[D\x1b[K")?; - return Ok(()); - } let (_, col) = term::cursor_pos(stdin)?; if col == size.ws_col - 1 { self.cursor_col = col - 1; write!(stdout(), "\x1b[D\x1b[K")?; return Ok(()); } + if self.line_offset == line.len() { + if col > self.cursor_col { + self.cursor_col = col; + } + return Ok(()); + } self.cursor_col = col; line.slice(self.line_offset, line.len()) .print(&mut stdout())?; |
