11using System ;
22using System . IO ;
33using System . Threading . Tasks ;
4-
4+ using Avalonia ;
55using Avalonia . Threading ;
6-
76using CommunityToolkit . Mvvm . ComponentModel ;
87
98namespace SourceGit . ViewModels
@@ -24,7 +23,64 @@ public bool IgnoreWhitespace
2423 {
2524 Preferences . Instance . IgnoreWhitespaceChangesInDiff = value ;
2625 OnPropertyChanged ( ) ;
27- LoadDiffContent ( ) ;
26+
27+ if ( _isTextDiff )
28+ LoadContent ( ) ;
29+ }
30+ }
31+ }
32+
33+ public bool ShowEntireFile
34+ {
35+ get => Preferences . Instance . UseFullTextDiff ;
36+ set
37+ {
38+ if ( value != Preferences . Instance . UseFullTextDiff )
39+ {
40+ Preferences . Instance . UseFullTextDiff = value ;
41+ OnPropertyChanged ( ) ;
42+
43+ if ( _isTextDiff )
44+ {
45+ if ( Content is CombinedTextDiff combined )
46+ combined . ScrollOffset = Vector . Zero ;
47+ else if ( Content is TwoSideTextDiff twoSide )
48+ twoSide . Data . File = string . Empty ;
49+
50+ LoadContent ( ) ;
51+ }
52+ }
53+ }
54+ }
55+
56+ public bool UseBlockNavigation
57+ {
58+ get => Preferences . Instance . UseBlockNavigationInDiffView ;
59+ set
60+ {
61+ if ( value != Preferences . Instance . UseBlockNavigationInDiffView )
62+ {
63+ Preferences . Instance . UseBlockNavigationInDiffView = value ;
64+ OnPropertyChanged ( ) ;
65+
66+ if ( Content is CombinedTextDiff combined )
67+ combined . BlockNavigation = value ? new BlockNavigation ( combined ) : null ;
68+ else if ( Content is TwoSideTextDiff twoSide )
69+ twoSide . BlockNavigation = value ? new BlockNavigation ( twoSide ) : null ;
70+ }
71+ }
72+ }
73+
74+ public bool UseSideBySide
75+ {
76+ get => Preferences . Instance . UseSideBySideDiff ;
77+ set
78+ {
79+ if ( value != Preferences . Instance . UseSideBySideDiff )
80+ {
81+ Preferences . Instance . UseSideBySideDiff = value ;
82+ OnPropertyChanged ( ) ;
83+ SwitchTextDiffMode ( ) ;
2884 }
2985 }
3086 }
@@ -72,33 +128,37 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
72128 else
73129 Title = $ "{ _option . OrgPath } → { _option . Path } ";
74130
75- LoadDiffContent ( ) ;
76- }
77-
78- public void ToggleFullTextDiff ( )
79- {
80- Preferences . Instance . UseFullTextDiff = ! Preferences . Instance . UseFullTextDiff ;
81- LoadDiffContent ( ) ;
131+ LoadContent ( ) ;
82132 }
83133
84134 public void IncrUnified ( )
85135 {
86136 UnifiedLines = _unifiedLines + 1 ;
87- LoadDiffContent ( ) ;
137+ LoadContent ( ) ;
88138 }
89139
90140 public void DecrUnified ( )
91141 {
92142 UnifiedLines = Math . Max ( 4 , _unifiedLines - 1 ) ;
93- LoadDiffContent ( ) ;
143+ LoadContent ( ) ;
94144 }
95145
96146 public void OpenExternalMergeTool ( )
97147 {
98148 new Commands . DiffTool ( _repo , _option ) . Open ( ) ;
99149 }
100150
101- private void LoadDiffContent ( )
151+ public void SwitchTextDiffMode ( )
152+ {
153+ var useSideBySide = Preferences . Instance . UseSideBySideDiff ;
154+ var hasBlockNavigation = Preferences . Instance . UseBlockNavigationInDiffView ;
155+ if ( useSideBySide && _content is CombinedTextDiff combined )
156+ Content = new TwoSideTextDiff ( combined . Data , hasBlockNavigation ) ;
157+ else if ( ! useSideBySide && _content is TwoSideTextDiff twoSide )
158+ Content = new CombinedTextDiff ( twoSide . Data , hasBlockNavigation ) ;
159+ }
160+
161+ private void LoadContent ( )
102162 {
103163 if ( _option . Path . EndsWith ( '/' ) )
104164 {
@@ -228,12 +288,23 @@ private void LoadDiffContent()
228288
229289 Dispatcher . UIThread . Post ( ( ) =>
230290 {
231- if ( _content is Models . TextDiff old && rs is Models . TextDiff cur && old . File == cur . File )
232- cur . ScrollOffset = old . ScrollOffset ;
233-
234291 FileModeChange = latest . FileModeChange ;
235- Content = rs ;
236- IsTextDiff = rs is Models . TextDiff ;
292+
293+ if ( rs is Models . TextDiff cur )
294+ {
295+ IsTextDiff = true ;
296+
297+ var hasBlockNavigation = Preferences . Instance . UseBlockNavigationInDiffView ;
298+ if ( Preferences . Instance . UseSideBySideDiff )
299+ Content = new TwoSideTextDiff ( cur , hasBlockNavigation , _content as TwoSideTextDiff ) ;
300+ else
301+ Content = new CombinedTextDiff ( cur , hasBlockNavigation , _content as CombinedTextDiff ) ;
302+ }
303+ else
304+ {
305+ IsTextDiff = false ;
306+ Content = rs ;
307+ }
237308 } ) ;
238309 } ) ;
239310 }
0 commit comments