diff --git a/src/completion.rs b/src/completion.rs index dc691094f12a346688f7a8c00ec311eab04b3419..9a5aa396721b977ebd31fe677445acf387d24397 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -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 { diff --git a/src/consts.rs b/src/consts.rs index dc743e14cea4c8afc1ba4c21098c0100004bb470..a73be123a1fb715bfdf6340cf58acf092fe7c5b8 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -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, diff --git a/src/lib.rs b/src/lib.rs index afc7cee6892fd89313698e77736150e5955b6386..e1cb2d164d79b4c39d57671aeac4bf57b71290fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)) { diff --git a/src/line_buffer.rs b/src/line_buffer.rs index 2007c16df67a8095031b54c171861e178e70f549..6ef7766816118aa17c8ee91c87c88ecbf6c1b21f 100644 --- a/src/line_buffer.rs +++ b/src/line_buffer.rs @@ -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]