Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
metiftikci committed Oct 28, 2023
1 parent 850eb3d commit 691b8e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/buffer/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ impl Buffer {

let mut pos: Option<TextPosition> = 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;
}
Expand All @@ -74,11 +70,7 @@ impl Buffer {

let mut pos: Option<TextPosition> = 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;
}
Expand Down
12 changes: 12 additions & 0 deletions src/core/text_position.rs
Original file line number Diff line number Diff line change
@@ -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<usize> {
Point::new(self.row, self.start)
}

pub fn get_end_point(&self) -> Point<usize> {
Point::new(self.row, self.end)
}
}

0 comments on commit 691b8e9

Please sign in to comment.