repline: Change newline behavior when not at end of input
TODO: This screws with the naming convention of home()/end()
This commit is contained in:
parent
dc1c9bdd6d
commit
a023551d9f
@ -237,9 +237,18 @@ impl<'a> Editor<'a> {
|
||||
self.head.len() + self.tail.len()
|
||||
}
|
||||
|
||||
/// Returns true if the cursor is at the beginning
|
||||
pub fn at_start(&self) -> bool {
|
||||
self.head.is_empty()
|
||||
}
|
||||
/// Returns true if the cursor is at the end
|
||||
pub fn at_end(&self) -> bool {
|
||||
self.tail.is_empty()
|
||||
}
|
||||
|
||||
/// Returns true if the buffer is empty.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.head.is_empty() && self.tail.is_empty()
|
||||
self.at_start() && self.at_end()
|
||||
}
|
||||
|
||||
/// Returns true if the buffer ends with a given pattern
|
||||
|
@ -5,7 +5,7 @@
|
||||
use crate::{editor::Editor, error::*, iter::*, raw::raw};
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
io::{stdout, Bytes, Read, Result, Write},
|
||||
io::{Bytes, Read, Result, Write, stdout},
|
||||
};
|
||||
|
||||
/// Prompts the user, reads the lines. Not much more to it than that.
|
||||
@ -81,7 +81,12 @@ impl<'a, R: Read> Repline<'a, R> {
|
||||
// ignore newlines, process line feeds. Not sure how cross-platform this is.
|
||||
'\n' => {}
|
||||
'\r' => {
|
||||
self.ed.push('\n', stdout)?;
|
||||
if self.ed.at_end() {
|
||||
self.ed.push('\n', stdout)?;
|
||||
} else {
|
||||
self.ed.end(stdout)?;
|
||||
writeln!(stdout)?;
|
||||
}
|
||||
return Ok(self.ed.to_string());
|
||||
}
|
||||
// Ctrl+Backspace in my terminal
|
||||
|
Loading…
x
Reference in New Issue
Block a user