From 691b8e9bc86fd22dce6a1a049b487c364795d58f Mon Sep 17 00:00:00 2001 From: metiftikci Date: Sun, 29 Oct 2023 01:47:28 +0300 Subject: [PATCH] refactor --- src/buffer/find.rs | 12 ++---------- src/core/text_position.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/buffer/find.rs b/src/buffer/find.rs index bc7895f..3eeeb3e 100644 --- a/src/buffer/find.rs +++ b/src/buffer/find.rs @@ -50,11 +50,7 @@ impl Buffer { let mut pos: Option = None; for find in self.finds.iter() { - if find.row < self.cursor.y { - continue; - } else if find.row == self.cursor.y && find.start <= self.cursor.x { - continue; - } else { + if find.get_start_point() > self.cursor { pos = Some(find.clone()); break; } @@ -74,11 +70,7 @@ impl Buffer { let mut pos: Option = None; for find in self.finds.iter().rev() { - if self.cursor.y < find.row { - continue; - } else if find.row == self.cursor.y && self.cursor.x <= find.start { - continue; - } else { + if self.cursor > find.get_end_point() { pos = Some(find.clone()); break; } diff --git a/src/core/text_position.rs b/src/core/text_position.rs index 2bd22ba..90af95f 100644 --- a/src/core/text_position.rs +++ b/src/core/text_position.rs @@ -1,6 +1,18 @@ +use crate::core::point::Point; + #[derive(Clone, Debug, Eq, PartialEq)] pub struct TextPosition { pub row: usize, pub start: usize, pub end: usize, } + +impl TextPosition { + pub fn get_start_point(&self) -> Point { + Point::new(self.row, self.start) + } + + pub fn get_end_point(&self) -> Point { + Point::new(self.row, self.end) + } +}