Skip to content

Commit

Permalink
Fix CSI bug in editor (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc authored Jul 23, 2023
1 parent 241eec4 commit 87a4988
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/usr/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ impl Editor {
},
'[' if escape => {
csi = true;
csi_params.clear();
continue;
},
'\0' => {
Expand Down Expand Up @@ -339,6 +340,8 @@ impl Editor {
let line = &self.lines[self.offset.y + self.cursor.y];
if line.is_empty() || self.cursor.x + self.offset.x >= line.chars().count() {
print!("\x1b[?25h"); // Enable cursor
escape = false;
csi = false;
continue
} else if self.cursor.x == self.cols() - 1 {
self.cursor.x = self.offset.x;
Expand All @@ -351,6 +354,8 @@ impl Editor {
'D' if csi => { // Arrow Left
if self.cursor.x + self.offset.x == 0 {
print!("\x1b[?25h"); // Enable cursor
escape = false;
csi = false;
continue;
} else if self.cursor.x == 0 {
self.cursor.x = self.offset.x - 1;
Expand Down Expand Up @@ -442,6 +447,8 @@ impl Editor {
} else { // Remove newline from previous line
if self.cursor.y == 0 && self.offset.y == 0 {
print!("\x1b[?25h"); // Enable cursor
escape = false;
csi = false;
continue;
}

Expand Down Expand Up @@ -504,13 +511,12 @@ impl Editor {
}
},
}
escape = false;
csi = false;
csi_params = String::new();
self.print_editing_status();
self.print_highlighted();
print!("\x1b[{};{}H", self.cursor.y + 1, self.cursor.x + 1);
print!("\x1b[?25h"); // Enable cursor
escape = false;
csi = false;
}
Ok(())
}
Expand Down

0 comments on commit 87a4988

Please sign in to comment.