diff --git a/src/git.rs b/src/git.rs index faf24c3..344722d 100644 --- a/src/git.rs +++ b/src/git.rs @@ -49,6 +49,7 @@ pub struct Commit { pub body: String, pub parent_commit_hashes: Vec, pub commit_type: CommitType, + pub line_number: usize, } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] @@ -267,7 +268,7 @@ fn load_all_commits(path: &Path, sort: SortCommit, stashes: &[Commit]) -> Vec Vec Vec { let mut commits = Vec::new(); - for bytes in reader.split(b'\0') { + for (i, bytes) in reader.split(b'\0').enumerate() { let bytes = bytes.unwrap(); let s = String::from_utf8_lossy(&bytes); @@ -337,6 +339,7 @@ fn load_all_stashes(path: &Path) -> Vec { body: parts[8].into(), parent_commit_hashes: parse_parent_commit_hashes(parts[9]), commit_type: CommitType::Stash, + line_number: i, }; commits.push(commit); diff --git a/src/widget/commit_list.rs b/src/widget/commit_list.rs index dd79fa6..a10f095 100644 --- a/src/widget/commit_list.rs +++ b/src/widget/commit_list.rs @@ -803,17 +803,20 @@ impl CommitList<'_> { commit.subject.to_string() }; + let line_number = commit.line_number + 1; // 1-based + let subject_with_line = format!("{:>4} | {}", line_number, subject); + let sub_spans = if let Some(pos) = state.search_matches[state.offset + i].subject.clone() { highlighted_spans( - subject, + subject_with_line, pos, self.color_theme.list_subject_fg, self.color_theme, truncate, ) } else { - vec![subject.into()] + vec![subject_with_line.into()] }; spans.extend(sub_spans)