Skip to content

Commit 66618dc

Browse files
committed
Added commit index for easier navigation
1 parent 0d75a3c commit 66618dc

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/git.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct Commit {
4949
pub body: String,
5050
pub parent_commit_hashes: Vec<CommitHash>,
5151
pub commit_type: CommitType,
52+
pub line_number: usize,
5253
}
5354

5455
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
@@ -267,7 +268,7 @@ fn load_all_commits(path: &Path, sort: SortCommit, stashes: &[Commit]) -> Vec<Co
267268

268269
let mut commits = Vec::new();
269270

270-
for bytes in reader.split(b'\0') {
271+
for (i, bytes) in reader.split(b'\0').enumerate() {
271272
let bytes = bytes.unwrap();
272273
let s = String::from_utf8_lossy(&bytes);
273274

@@ -288,6 +289,7 @@ fn load_all_commits(path: &Path, sort: SortCommit, stashes: &[Commit]) -> Vec<Co
288289
body: parts[8].into(),
289290
parent_commit_hashes: parse_parent_commit_hashes(parts[9]),
290291
commit_type: CommitType::Commit,
292+
line_number: i,
291293
};
292294

293295
commits.push(commit);
@@ -316,7 +318,7 @@ fn load_all_stashes(path: &Path) -> Vec<Commit> {
316318

317319
let mut commits = Vec::new();
318320

319-
for bytes in reader.split(b'\0') {
321+
for (i, bytes) in reader.split(b'\0').enumerate() {
320322
let bytes = bytes.unwrap();
321323
let s = String::from_utf8_lossy(&bytes);
322324

@@ -337,6 +339,7 @@ fn load_all_stashes(path: &Path) -> Vec<Commit> {
337339
body: parts[8].into(),
338340
parent_commit_hashes: parse_parent_commit_hashes(parts[9]),
339341
commit_type: CommitType::Stash,
342+
line_number: i,
340343
};
341344

342345
commits.push(commit);

src/widget/commit_list.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,17 +803,20 @@ impl CommitList<'_> {
803803
commit.subject.to_string()
804804
};
805805

806+
let line_number = commit.line_number + 1; // 1-based
807+
let subject_with_line = format!("{:>4} | {}", line_number, subject);
808+
806809
let sub_spans =
807810
if let Some(pos) = state.search_matches[state.offset + i].subject.clone() {
808811
highlighted_spans(
809-
subject,
812+
subject_with_line,
810813
pos,
811814
self.color_theme.list_subject_fg,
812815
self.color_theme,
813816
truncate,
814817
)
815818
} else {
816-
vec![subject.into()]
819+
vec![subject_with_line.into()]
817820
};
818821

819822
spans.extend(sub_spans)

0 commit comments

Comments
 (0)