diff --git a/src/nvim.rs b/src/nvim.rs index cfb99b1..2d6b2e2 100644 --- a/src/nvim.rs +++ b/src/nvim.rs @@ -258,7 +258,7 @@ impl ErrorReport for result::Result { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum RepaintMode { Nothing, All, @@ -267,6 +267,7 @@ pub enum RepaintMode { } impl RepaintMode { + // [TODO]: Remove clones - 2017-04-22 09:46 pub fn join(&self, mode: &RepaintMode) -> RepaintMode { match (self, mode) { (&RepaintMode::Nothing, m) => m.clone(), @@ -278,8 +279,12 @@ impl RepaintMode { vec.join(mr2); RepaintMode::AreaList(vec) } - (&RepaintMode::AreaList(_), &RepaintMode::AreaList(_)) => { - panic!("Not implmeneted"); + (&RepaintMode::AreaList(ref target), &RepaintMode::AreaList(ref source)) => { + let mut list = target.clone(); + for s in &source.list { + list.join(&s); + } + RepaintMode::AreaList(list) } (&RepaintMode::AreaList(ref l1), &RepaintMode::Area(ref l2)) => { let mut list = l1.clone(); diff --git a/src/shell.rs b/src/shell.rs index e66e780..cee3090 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -702,7 +702,7 @@ fn gtk_configure_event(state: &Arc>, ev: &EventConfigure) -> bool impl RedrawEvents for State { fn on_cursor_goto(&mut self, row: u64, col: u64) -> RepaintMode { - RepaintMode::Area(self.model.set_cursor(row as usize, col as usize)) + RepaintMode::AreaList(self.model.set_cursor(row as usize, col as usize)) } fn on_put(&mut self, text: &str) -> RepaintMode { diff --git a/src/ui_model.rs b/src/ui_model.rs index 1b72252..0b603fa 100644 --- a/src/ui_model.rs +++ b/src/ui_model.rs @@ -138,8 +138,8 @@ impl UiModel { ModelRect::point(self.cur_col, self.cur_row) } - pub fn set_cursor(&mut self, row: usize, col: usize) -> ModelRect { - let mut changed_region = self.cur_point(); + pub fn set_cursor(&mut self, row: usize, col: usize) -> ModelRectVec { + let mut changed_region = ModelRectVec::new(self.cur_point()); self.cur_row = row; self.cur_col = col; @@ -230,7 +230,7 @@ impl UiModel { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ModelRectVec { pub list: Vec, } @@ -249,7 +249,9 @@ impl ModelRectVec { rect.right == neighbor.right + 1) && neighbor.in_vertical(rect) { return Some(i); - } else if rect == neighbor { + } else if rect.in_horizontal(neighbor) && rect.in_vertical(neighbor) { + return Some(i); + } else if rect.contains(neighbor) { return Some(i); } } @@ -307,6 +309,13 @@ impl ModelRect { other.bot >= self.top && other.bot <= self.bot } + fn contains(&self, other: &ModelRect) -> bool { + self.top <= other.top && + self.bot >= other.bot && + self.left <= other.left && + self.right >= other.right + } + pub fn extend(&mut self, top: usize, bot: usize, left: usize, right: usize) { if self.top > 0 { self.top -= top; @@ -466,6 +475,16 @@ impl<'a> Iterator for ClipColIterator<'a> { mod tests { use super::*; + #[test] + fn test_vec_join_inside() { + let mut list = ModelRectVec::new(ModelRect::new(0, 23, 0, 69)); + + let inside = ModelRect::new(23, 23, 68, 69); + + list.join(&inside); + assert_eq!(1, list.list.len()); + } + #[test] fn test_vec_join_top() { let mut list = ModelRectVec::new(ModelRect::point(0, 0)); @@ -476,6 +495,26 @@ mod tests { assert_eq!(1, list.list.len()); } + #[test] + fn test_model_vec_join_right() { + let mut list = ModelRectVec::new(ModelRect::new(23, 23, 69, 69)); + + let neighbor = ModelRect::new(23, 23, 69, 70); + + list.join(&neighbor); + assert_eq!(1, list.list.len()); + } + + #[test] + fn test_model_vec_join_right2() { + let mut list = ModelRectVec::new(ModelRect::new(0, 1, 0, 9)); + + let neighbor = ModelRect::new(1, 1, 9, 10); + + list.join(&neighbor); + assert_eq!(1, list.list.len()); + } + #[test] fn test_model_vec_join() { let mut list = ModelRectVec::new(ModelRect::point(5, 5)); @@ -558,10 +597,18 @@ mod tests { let rect = model.set_cursor(5, 5); - assert_eq!(1, rect.top); - assert_eq!(1, rect.left); - assert_eq!(5, rect.bot); - assert_eq!(5, rect.right); + assert_eq!(2, rect.list.len()); + + assert_eq!(1, rect.list[0].top); + assert_eq!(1, rect.list[0].left); + assert_eq!(1, rect.list[0].bot); + assert_eq!(1, rect.list[0].right); + + + assert_eq!(5, rect.list[1].top); + assert_eq!(5, rect.list[1].left); + assert_eq!(5, rect.list[1].bot); + assert_eq!(5, rect.list[1].right); } #[test]