@@ -12,15 +12,24 @@ public class Blame : ObservableObject
12
12
{
13
13
public string Title
14
14
{
15
- get ;
16
- private set ;
15
+ get => _title ;
16
+ private set => SetProperty ( ref _title , value ) ;
17
17
}
18
18
19
19
public bool IsBinary
20
20
{
21
21
get => _data != null && _data . IsBinary ;
22
22
}
23
23
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
+
24
33
public Models . BlameData Data
25
34
{
26
35
get => _data ;
@@ -30,20 +39,60 @@ public Models.BlameData Data
30
39
public Blame ( string repo , string file , string revision )
31
40
{
32
41
_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 } ";
33
50
34
- Title = $ "{ file } @ { revision . AsSpan ( 0 , 10 ) } ";
35
51
Task . Run ( ( ) =>
36
52
{
37
- var result = new Commands . Blame ( repo , file , revision ) . Result ( ) ;
53
+ var result = new Commands . Blame ( _repo , _file , commitSHA ) . Result ( ) ;
38
54
Dispatcher . UIThread . Invoke ( ( ) =>
39
55
{
40
56
Data = result ;
41
57
OnPropertyChanged ( nameof ( IsBinary ) ) ;
42
58
} ) ;
43
59
} ) ;
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 ) ;
44
93
}
45
94
46
- public void NavigateToCommit ( string commitSHA )
95
+ public void NavigateToCommit ( string commitSHA , bool resetHistoryForward )
47
96
{
48
97
var launcher = App . GetLauncher ( ) ;
49
98
if ( launcher == null )
@@ -54,6 +103,7 @@ public void NavigateToCommit(string commitSHA)
54
103
if ( page . Data is Repository repo && repo . FullPath . Equals ( _repo ) )
55
104
{
56
105
repo . NavigateToCommit ( commitSHA ) ;
106
+ SetBlameData ( commitSHA , resetHistoryForward ) ;
57
107
break ;
58
108
}
59
109
}
@@ -69,7 +119,11 @@ public string GetCommitMessage(string sha)
69
119
return msg ;
70
120
}
71
121
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 = [ ] ;
73
127
private Models . BlameData _data = null ;
74
128
private Dictionary < string , string > _commitMessages = new Dictionary < string , string > ( ) ;
75
129
}
0 commit comments