Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
metiftikci committed Oct 22, 2023
1 parent d0c38f1 commit 735c747
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
24 changes: 8 additions & 16 deletions src/buffer/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,21 @@ impl Buffer {
let mut list: Vec<Highlight> = vec![];

list.push(Highlight {
name: "SelectedLine",
name: "CurrentLine",
row: self.cursor.x,
start: self.scroll.x,
end: self.text_area.width as usize,
});

if self.lines.len() == 0 {
panic!("I have no lines");
if let Some(end) = self.get_current_line_last_char_index() {
list.push(Highlight {
name: "CurrentLineText",
row: self.cursor.y,
start: 0,
end,
});
}

let mut end = self.get_line(self.cursor.y).len();

if end > 0 {
end -= 1;
}

list.push(Highlight {
name: "SelectedLineText",
row: self.cursor.y,
start: 0,
end,
});

list
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/buffer/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ impl Buffer {
self.get_current_line().len()
}

pub fn get_line_last_char_index(&self, row: usize) -> Option<usize> {
let line = self.lines.get(row)?;
match line.len() {
0 => None,
length => Some(length - 1),
}
}

pub fn get_current_line_last_char_index(&self) -> Option<usize> {
self.get_line_last_char_index(self.cursor.y)
}

pub fn get_row_count(&self) -> usize {
self.lines.len()
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/find_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl FindFileCommand {
files_popup.options.show_info_column = false;
files_popup.set_size(files_popup.area.clone()); // TODO: Move
files_popup.styles.insert(
"SelectedLineText",
"CurrentLineText",
Style {
fg: (88, 129, 87),
bg: SILVER,
Expand Down

0 comments on commit 735c747

Please sign in to comment.