diff --git a/src/buffer/highlight.rs b/src/buffer/highlight.rs index 06d2670..db0dde3 100644 --- a/src/buffer/highlight.rs +++ b/src/buffer/highlight.rs @@ -21,29 +21,21 @@ impl Buffer { let mut list: Vec = 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 } } diff --git a/src/buffer/text.rs b/src/buffer/text.rs index 21973cf..c4b232d 100644 --- a/src/buffer/text.rs +++ b/src/buffer/text.rs @@ -53,6 +53,18 @@ impl Buffer { self.get_current_line().len() } + pub fn get_line_last_char_index(&self, row: usize) -> Option { + 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 { + self.get_line_last_char_index(self.cursor.y) + } + pub fn get_row_count(&self) -> usize { self.lines.len() } diff --git a/src/commands/find_file.rs b/src/commands/find_file.rs index 09ea05f..d5a3c9e 100644 --- a/src/commands/find_file.rs +++ b/src/commands/find_file.rs @@ -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,