Skip to content

Commit 6bdab9d

Browse files
andrea-berlingextrawurst
authored andcommitted
Preserve BlameProcess in BlamePopup when jumping lines
Add Context enum to keep the blame status across line jumps Add a context field to the GotoLinePopup Add blame field to BlameFilePopup Use the blame field in BlameFilePopup.open if not None
1 parent 55da5d9 commit 6bdab9d

File tree

10 files changed

+59
-24
lines changed

10 files changed

+59
-24
lines changed

asyncgit/src/blame.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,25 @@ use std::{
1414
};
1515

1616
///
17-
#[derive(Hash, Clone, PartialEq, Eq)]
17+
#[derive(Hash, Clone, PartialEq, Eq, Debug)]
1818
pub struct BlameParams {
1919
/// path to the file to blame
2020
pub file_path: String,
2121
/// blame at a specific revision
2222
pub commit_id: Option<CommitId>,
2323
}
2424

25+
#[derive(Debug)]
2526
struct Request<R, A>(R, Option<A>);
2627

27-
#[derive(Default, Clone)]
28+
#[derive(Debug, Default, Clone)]
2829
struct LastResult<P, R> {
2930
params: P,
3031
result: R,
3132
}
3233

3334
///
35+
#[derive(Debug, Clone)]
3436
pub struct AsyncBlame {
3537
current: Arc<Mutex<Request<u64, FileBlame>>>,
3638
last: Arc<Mutex<Option<LastResult<BlameParams, FileBlame>>>>,

src/app.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
TagListPopup,
2222
},
2323
queue::{
24-
Action, AppTabs, InternalEvent, NeedsUpdate, Queue,
24+
Action, AppTabs, Context, InternalEvent, NeedsUpdate, Queue,
2525
StackablePopupOpen,
2626
},
2727
setup_popups,
@@ -675,8 +675,8 @@ impl App {
675675
StackablePopupOpen::CompareCommits(param) => {
676676
self.compare_commits_popup.open(param)?;
677677
}
678-
StackablePopupOpen::GotoLine => {
679-
self.goto_line_popup.open();
678+
StackablePopupOpen::GotoLine(context) => {
679+
self.goto_line_popup.open(Some(context));
680680
}
681681
}
682682

@@ -880,7 +880,7 @@ impl App {
880880
InternalEvent::CommitSearch(options) => {
881881
self.revlog.search(options);
882882
}
883-
InternalEvent::GotoLine(line) => {
883+
InternalEvent::GotoLine(line, context) => {
884884
if let Some(popup) = self.popup_stack.pop() {
885885
if let StackablePopupOpen::BlameFile(params) =
886886
popup
@@ -889,6 +889,12 @@ impl App {
889889
StackablePopupOpen::BlameFile(
890890
BlameFileOpen {
891891
selection: Some(line),
892+
blame: context.and_then(|ctx| {
893+
let Context::Blame(
894+
blame_process,
895+
) = ctx;
896+
blame_process
897+
}),
892898
..params
893899
},
894900
),

src/components/revision_files.rs

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ impl RevisionFilesComponent {
193193
file_path: path,
194194
commit_id: self.revision.as_ref().map(|c| c.id),
195195
selection: None,
196+
blame: None,
196197
}),
197198
));
198199

src/components/status_tree.rs

+1
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ impl Component for StatusTreeComponent {
456456
file_path: status_item.path,
457457
commit_id: self.revision,
458458
selection: None,
459+
blame: None,
459460
},
460461
),
461462
));

src/popups/blame_file.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
},
88
keys::{key_match, SharedKeyConfig},
99
popups::{FileRevOpen, InspectCommitOpen},
10-
queue::{InternalEvent, Queue, StackablePopupOpen},
10+
queue::{Context, InternalEvent, Queue, StackablePopupOpen},
1111
string_utils::tabs_to_spaces,
1212
strings,
1313
ui::{self, style::SharedTheme, AsyncSyntaxJob, SyntaxText},
@@ -35,7 +35,8 @@ static NO_AUTHOR: &str = "<no author>";
3535
static MIN_AUTHOR_WIDTH: usize = 3;
3636
static MAX_AUTHOR_WIDTH: usize = 20;
3737

38-
struct SyntaxFileBlame {
38+
#[derive(Debug, Clone)]
39+
pub struct SyntaxFileBlame {
3940
pub file_blame: FileBlame,
4041
pub styled_text: Option<SyntaxText>,
4142
}
@@ -54,7 +55,8 @@ impl SyntaxFileBlame {
5455
}
5556
}
5657

57-
enum BlameProcess {
58+
#[derive(Clone, Debug)]
59+
pub enum BlameProcess {
5860
GettingBlame(AsyncBlame),
5961
SyntaxHighlighting {
6062
unstyled_file_blame: SyntaxFileBlame,
@@ -81,6 +83,7 @@ pub struct BlameFileOpen {
8183
pub file_path: String,
8284
pub commit_id: Option<CommitId>,
8385
pub selection: Option<usize>,
86+
pub blame: Option<BlameProcess>,
8487
}
8588

8689
pub struct BlameFilePopup {
@@ -324,7 +327,9 @@ impl Component for BlameFilePopup {
324327
self.hide_stacked(true);
325328
self.visible = true;
326329
self.queue.push(InternalEvent::OpenPopup(
327-
StackablePopupOpen::GotoLine,
330+
StackablePopupOpen::GotoLine(Context::Blame(
331+
self.blame.clone(),
332+
)),
328333
));
329334
}
330335

@@ -375,6 +380,7 @@ impl BlameFilePopup {
375380
file_path: request.file_path,
376381
commit_id: request.commit_id,
377382
selection: self.get_selection(),
383+
blame: self.blame.clone(),
378384
}),
379385
));
380386
}
@@ -390,11 +396,15 @@ impl BlameFilePopup {
390396
file_path: open.file_path,
391397
commit_id: open.commit_id,
392398
});
393-
self.blame =
394-
Some(BlameProcess::GettingBlame(AsyncBlame::new(
395-
self.repo.borrow().clone(),
396-
&self.git_sender,
397-
)));
399+
self.blame = match open.blame {
400+
None => {
401+
Some(BlameProcess::GettingBlame(AsyncBlame::new(
402+
self.repo.borrow().clone(),
403+
&self.git_sender,
404+
)))
405+
}
406+
blame => blame,
407+
};
398408
self.table_state.get_mut().select(Some(0));
399409
self.visible = true;
400410
self.update()?;
@@ -457,7 +467,6 @@ impl BlameFilePopup {
457467
),
458468
},
459469
);
460-
self.set_open_selection();
461470
self.highlight_blame_lines();
462471

463472
return Ok(());
@@ -468,6 +477,7 @@ impl BlameFilePopup {
468477
}
469478
}
470479
}
480+
self.set_open_selection();
471481

472482
Ok(())
473483
}

src/popups/file_revlog.rs

+1
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ impl Component for FileRevlogPopup {
536536
file_path: open_request.file_path,
537537
commit_id: self.selected_commit(),
538538
selection: None,
539+
blame: None,
539540
},
540541
),
541542
));

src/popups/goto_line.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
DrawableComponent, EventState,
66
},
77
keys::{key_match, SharedKeyConfig},
8-
queue::{InternalEvent, Queue},
8+
queue::{Context, InternalEvent, Queue},
99
ui::{self, style::SharedTheme},
1010
};
1111

@@ -25,6 +25,7 @@ pub struct GotoLinePopup {
2525
key_config: SharedKeyConfig,
2626
queue: Queue,
2727
theme: SharedTheme,
28+
context: Option<Context>,
2829
}
2930

3031
impl GotoLinePopup {
@@ -35,11 +36,13 @@ impl GotoLinePopup {
3536
key_config: env.key_config.clone(),
3637
queue: env.queue.clone(),
3738
theme: env.theme.clone(),
39+
context: None,
3840
}
3941
}
4042

41-
pub fn open(&mut self) {
43+
pub fn open(&mut self, context: Option<Context>) {
4244
self.visible = true;
45+
self.context = context;
4346
}
4447
}
4548

@@ -80,6 +83,7 @@ impl Component for GotoLinePopup {
8083
if !self.line.is_empty() {
8184
self.queue.push(InternalEvent::GotoLine(
8285
self.line.parse::<usize>().expect("This shouldn't happen since the input is constrained to ascii digits only"),
86+
self.context.clone()
8387
));
8488
}
8589
self.queue.push(InternalEvent::PopupStackPop);

src/popups/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mod submodules;
2525
mod tag_commit;
2626
mod taglist;
2727

28-
pub use blame_file::{BlameFileOpen, BlameFilePopup};
28+
pub use blame_file::{BlameFileOpen, BlameFilePopup, BlameProcess};
2929
pub use branchlist::BranchListPopup;
3030
pub use commit::CommitPopup;
3131
pub use compare_commits::CompareCommitsPopup;

src/queue.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
22
components::FuzzyFinderTarget,
33
popups::{
4-
AppOption, BlameFileOpen, FileRevOpen, FileTreeOpen,
5-
InspectCommitOpen,
4+
AppOption, BlameFileOpen, BlameProcess, FileRevOpen,
5+
FileTreeOpen, InspectCommitOpen,
66
},
77
tabs::StashingOptions,
88
};
@@ -56,6 +56,13 @@ pub enum Action {
5656
UndoCommit,
5757
}
5858

59+
#[derive(Debug, Clone)]
60+
pub enum Context {
61+
Blame(Option<BlameProcess>),
62+
//FileView,
63+
//PossibleRange(u32, u32),
64+
}
65+
5966
#[derive(Debug)]
6067
pub enum StackablePopupOpen {
6168
///
@@ -69,7 +76,7 @@ pub enum StackablePopupOpen {
6976
///
7077
CompareCommits(InspectCommitOpen),
7178
///
72-
GotoLine,
79+
GotoLine(Context),
7380
}
7481

7582
pub enum AppTabs {
@@ -149,7 +156,7 @@ pub enum InternalEvent {
149156
///
150157
CommitSearch(LogFilterSearchOptions),
151158
///
152-
GotoLine(usize),
159+
GotoLine(usize, Option<Context>),
153160
}
154161

155162
/// single threaded simple queue for components to communicate with each other

src/ui/syntax_text.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ use syntect::{
2222

2323
use crate::{AsyncAppNotification, SyntaxHighlightProgress};
2424

25+
#[derive(Debug, Clone)]
2526
struct SyntaxLine {
2627
items: Vec<(Style, usize, Range<usize>)>,
2728
}
2829

30+
#[derive(Debug, Clone)]
2931
pub struct SyntaxText {
3032
text: String,
3133
lines: Vec<SyntaxLine>,
@@ -211,12 +213,13 @@ fn syntact_style_to_tui(style: &Style) -> ratatui::style::Style {
211213
res
212214
}
213215

216+
#[derive(Debug)]
214217
enum JobState {
215218
Request((String, String)),
216219
Response(SyntaxText),
217220
}
218221

219-
#[derive(Clone, Default)]
222+
#[derive(Clone, Default, Debug)]
220223
pub struct AsyncSyntaxJob {
221224
state: Arc<Mutex<Option<JobState>>>,
222225
}

0 commit comments

Comments
 (0)