From 83b5798f6f9251e666238e4d379f223219751819 Mon Sep 17 00:00:00 2001 From: daa Date: Sun, 23 Apr 2017 13:42:05 +0300 Subject: [PATCH] Small code cleanup --- src/shell.rs | 4 +--- src/ui_model.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/shell.rs b/src/shell.rs index 8553731..dcb8385 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -533,9 +533,7 @@ fn draw(state: &State, ctx: &cairo::Context) { ctx.move_to(line_x, line_y); for (col_idx, cell) in line.iter() { - let double_width = line.get(col_idx + 1) - .map(|c| c.attrs.double_width) - .unwrap_or(false); + let double_width = line.is_double_width(col_idx); let current_point = ctx.get_current_point(); let (bg, fg) = state.colors(cell); diff --git a/src/ui_model.rs b/src/ui_model.rs index 0b603fa..f16682b 100644 --- a/src/ui_model.rs +++ b/src/ui_model.rs @@ -310,9 +310,7 @@ impl ModelRect { } fn contains(&self, other: &ModelRect) -> bool { - self.top <= other.top && - self.bot >= other.bot && - self.left <= other.left && + self.top <= other.top && self.bot >= other.bot && self.left <= other.left && self.right >= other.right } @@ -435,6 +433,13 @@ impl<'a> ClipLine<'a> { } } + #[inline] + pub fn is_double_width(&self, col_idx: usize) -> bool { + self.get(col_idx + 1) + .map(|c| c.attrs.double_width) + .unwrap_or(false) + } + pub fn get(&self, idx: usize) -> Option<&Cell> { self.line.get(idx) } @@ -477,7 +482,7 @@ mod tests { #[test] fn test_vec_join_inside() { - let mut list = ModelRectVec::new(ModelRect::new(0, 23, 0, 69)); + let mut list = ModelRectVec::new(ModelRect::new(0, 23, 0, 69)); let inside = ModelRect::new(23, 23, 68, 69);