Skip to content
Snippets Groups Projects
Commit dec0e7f5 authored by gwenn's avatar gwenn
Browse files

Fix character transposition and add quoted insert

parent aae5b080
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,6 @@ use line_buffer::LineBuffer;
// TODO: let the implementers choose/find word boudaries ???
// (line, pos) is like (rl_line_buffer, rl_point) to make contextual completion ("select t.na| from tbl as t")
// TOOD: make &self &mut self ???
// TODO: change update signature: _line: Into<String>
/// To be called for tab-completion.
pub trait Completer {
......
......@@ -22,6 +22,7 @@ pub enum KeyPress {
CTRL_S,
CTRL_T,
CTRL_U,
CTRL_V,
CTRL_W,
CTRL_Y,
CTRL_Z,
......@@ -62,6 +63,7 @@ pub fn char_to_key_press(c: char) -> KeyPress {
'\x13' => KeyPress::CTRL_S,
'\x14' => KeyPress::CTRL_T,
'\x15' => KeyPress::CTRL_U,
'\x16' => KeyPress::CTRL_V,
'\x17' => KeyPress::CTRL_W,
'\x19' => KeyPress::CTRL_Y,
'\x1a' => KeyPress::CTRL_Z,
......
......@@ -833,7 +833,13 @@ fn readline_edit(prompt: &str,
kill_ring.kill(&text, false)
}
}
// TODO CTRL_V // Quoted insert
KeyPress::CTRL_V => {
// Quoted insert
kill_ring.reset();
let c = chars.next().unwrap();
let ch = try!(c);
try!(edit_insert(&mut s, ch))
}
KeyPress::CTRL_W => {
// Kill the word behind point, using white space as a word boundary
if let Some(text) = try!(edit_delete_prev_word(&mut s, char::is_whitespace)) {
......
......@@ -225,10 +225,12 @@ impl LineBuffer {
/// Exchange the char before cursor with the character at cursor.
pub fn transpose_chars(&mut self) -> bool {
if self.pos == 0 || self.pos == self.buf.len() {
// TODO should work even if s.pos == s.buf.len()
if self.pos == 0 || self.buf.chars().count() < 2 {
return false;
}
if self.pos == self.buf.len() {
self.move_left();
}
let ch = self.buf.remove(self.pos);
let size = ch.len_utf8();
let other_ch = self.char_before_cursor().unwrap();
......@@ -502,6 +504,13 @@ mod test {
assert_eq!("acß", s.buf);
assert_eq!(2, s.pos);
assert_eq!(true, ok);
s.buf = String::from("aßc");
s.pos = 4;
let ok = s.transpose_chars();
assert_eq!("acß", s.buf);
assert_eq!(2, s.pos);
assert_eq!(true, ok);
}
#[test]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment