@@ -12,15 +12,24 @@ public class Blame : ObservableObject
1212 {
1313 public string Title
1414 {
15- get ;
16- private set ;
15+ get => _title ;
16+ private set => SetProperty ( ref _title , value ) ;
1717 }
1818
1919 public bool IsBinary
2020 {
2121 get => _data != null && _data . IsBinary ;
2222 }
2323
24+ public bool CanMoveBack
25+ {
26+ get => _shaHistoryIndex > 0 && _shaHistory . Count > 1 ;
27+ }
28+ public bool CanMoveForward
29+ {
30+ get => _shaHistoryIndex < _shaHistory . Count - 1 ;
31+ }
32+
2433 public Models . BlameData Data
2534 {
2635 get => _data ;
@@ -30,20 +39,60 @@ public Models.BlameData Data
3039 public Blame ( string repo , string file , string revision )
3140 {
3241 _repo = repo ;
42+ _file = file ;
43+
44+ SetBlameData ( $ "{ revision . AsSpan ( 0 , 10 ) } ", true ) ;
45+ }
46+
47+ private void SetBlameData ( string commitSHA , bool resetHistoryForward )
48+ {
49+ Title = $ "{ _file } @ { commitSHA } ";
3350
34- Title = $ "{ file } @ { revision . AsSpan ( 0 , 10 ) } ";
3551 Task . Run ( ( ) =>
3652 {
37- var result = new Commands . Blame ( repo , file , revision ) . Result ( ) ;
53+ var result = new Commands . Blame ( _repo , _file , commitSHA ) . Result ( ) ;
3854 Dispatcher . UIThread . Invoke ( ( ) =>
3955 {
4056 Data = result ;
4157 OnPropertyChanged ( nameof ( IsBinary ) ) ;
4258 } ) ;
4359 } ) ;
60+
61+ if ( resetHistoryForward )
62+ {
63+ if ( _shaHistoryIndex < _shaHistory . Count - 1 )
64+ _shaHistory . RemoveRange ( _shaHistoryIndex + 1 , _shaHistory . Count - _shaHistoryIndex - 1 ) ;
65+
66+ if ( _shaHistory . Count == 0 || _shaHistory [ _shaHistoryIndex ] != commitSHA )
67+ {
68+ _shaHistory . Add ( commitSHA ) ;
69+ _shaHistoryIndex = _shaHistory . Count - 1 ;
70+ }
71+ }
72+
73+ OnPropertyChanged ( nameof ( CanMoveBack ) ) ;
74+ OnPropertyChanged ( nameof ( CanMoveForward ) ) ;
75+ }
76+
77+ public void Back ( )
78+ {
79+ -- _shaHistoryIndex ;
80+ if ( _shaHistoryIndex < 0 )
81+ _shaHistoryIndex = 0 ;
82+
83+ NavigateToCommit ( _shaHistory [ _shaHistoryIndex ] , false ) ;
84+ }
85+
86+ public void Forward ( )
87+ {
88+ ++ _shaHistoryIndex ;
89+ if ( _shaHistoryIndex >= _shaHistory . Count )
90+ _shaHistoryIndex = _shaHistory . Count - 1 ;
91+
92+ NavigateToCommit ( _shaHistory [ _shaHistoryIndex ] , false ) ;
4493 }
4594
46- public void NavigateToCommit ( string commitSHA )
95+ public void NavigateToCommit ( string commitSHA , bool resetHistoryForward )
4796 {
4897 var launcher = App . GetLauncher ( ) ;
4998 if ( launcher == null )
@@ -54,6 +103,7 @@ public void NavigateToCommit(string commitSHA)
54103 if ( page . Data is Repository repo && repo . FullPath . Equals ( _repo ) )
55104 {
56105 repo . NavigateToCommit ( commitSHA ) ;
106+ SetBlameData ( commitSHA , resetHistoryForward ) ;
57107 break ;
58108 }
59109 }
@@ -69,7 +119,11 @@ public string GetCommitMessage(string sha)
69119 return msg ;
70120 }
71121
72- private readonly string _repo ;
122+ private string _repo ;
123+ private string _file ;
124+ private string _title ;
125+ private int _shaHistoryIndex = 0 ;
126+ private List < string > _shaHistory = [ ] ;
73127 private Models . BlameData _data = null ;
74128 private Dictionary < string , string > _commitMessages = new Dictionary < string , string > ( ) ;
75129 }
0 commit comments