diff --git a/lapce-core/src/lens.rs b/lapce-core/src/lens.rs index d25fb702..6d981e6b 100644 --- a/lapce-core/src/lens.rs +++ b/lapce-core/src/lens.rs @@ -53,10 +53,7 @@ pub fn line_of_height(&self, height: usize) -> usize { } pub fn height_of_line(&self, line: usize) -> usize { - let max_line = self.0.len(); - if line >= max_line { - return self.0.count::(self.0.len()); - } + let line = self.0.len().min(line); self.0.count::(line) } diff --git a/lapce-data/src/editor.rs b/lapce-data/src/editor.rs index b24d2a05..4fde632a 100644 --- a/lapce-data/src/editor.rs +++ b/lapce-data/src/editor.rs @@ -905,7 +905,7 @@ fn next_diff(&mut self, ctx: &mut EventCtx) { let (path, offset) = next_in_file_diff_offset(offset, buffer_path, &diff_files); let location = EditorLocation { - path, + path: path.to_path_buf(), position: Some(offset), scroll_offset: None, history: Some("head".to_string()), @@ -2433,24 +2433,24 @@ pub struct HighlightTextLayout { pub highlights: Vec<(usize, usize, String)>, } -fn next_in_file_diff_offset( +fn next_in_file_diff_offset<'a>( offset: usize, path: &Path, - file_diffs: &[(PathBuf, Vec)], -) -> (PathBuf, usize) { + file_diffs: &'a [(PathBuf, Vec)], +) -> (&'a Path, usize) { for (current_path, offsets) in file_diffs { if path == current_path { for diff_offset in offsets { if *diff_offset > offset { - return ((*current_path).clone(), *diff_offset); + return (current_path.as_ref(), *diff_offset); } } } if current_path > path { - return ((*current_path).clone(), offsets[0]); + return (current_path.as_ref(), offsets[0]); } } - ((file_diffs[0].0).clone(), file_diffs[0].1[0]) + (file_diffs[0].0.as_ref(), file_diffs[0].1[0]) } fn next_in_file_errors_offset(