some more line movements

parse-tree
Jordan Orelli 2 years ago
parent 3fd068d4c8
commit 1eb955b474

@ -68,6 +68,21 @@ impl Line {
}
}
/// moves the cursor to the start of the edit line, returning the old cursor value
pub fn seek_left(&mut self) -> usize {
let n = self.cursor;
self.cursor = 0;
self.show_debug();
n
}
pub fn seek_right(&mut self) -> usize {
let n = self.chars.len() - self.cursor;
self.cursor = self.chars.len();
self.show_debug();
n
}
pub fn forward(&mut self) -> bool {
if self.cursor < self.chars.len() {
self.cursor += 1;

@ -388,7 +388,7 @@ fn main() -> Result<()> {
// CTRL-U to erase to the beginning of the line
if event.ctrl && event.code == key::U {
info!("» clear-left");
info!("» clear left");
let n = line.clear_left();
if n > 0 {
// move left by the number of elements removed
@ -411,6 +411,34 @@ fn main() -> Result<()> {
continue;
}
// CTRL-A to move to the beginning of the line
if event.ctrl && event.code == key::A {
info!("» seek left");
let n = line.seek_left();
if n > 0 {
// move left by the distance seeked
let text = format!("\x1b[{}D", n);
unsafe {
Error::check(Console::WriteConsoleA(stdout, text.as_bytes(), None, None))?;
}
}
continue;
}
// CTRL-E to move to the end of the line
if event.ctrl && event.code == key::E {
info!("» seek right");
let n = line.seek_right();
if n > 0 {
// move right by the distance seeked
let text = format!("\x1b[{}C", n);
unsafe {
Error::check(Console::WriteConsoleA(stdout, text.as_bytes(), None, None))?;
}
}
continue;
}
// TODO: something better here, this is crappy. I should be checking characters
// based on their unicode categories, not this garbo
if !event.char.is_control() {

Loading…
Cancel
Save