11using System ;
22using System . IO ;
33using System . Threading . Tasks ;
4-
54using Avalonia . Threading ;
6-
75using CommunityToolkit . Mvvm . ComponentModel ;
86
97namespace SourceGit . ViewModels
@@ -24,7 +22,58 @@ public bool IgnoreWhitespace
2422 {
2523 Preferences . Instance . IgnoreWhitespaceChangesInDiff = value ;
2624 OnPropertyChanged ( ) ;
27- LoadDiffContent ( ) ;
25+
26+ if ( _isTextDiff )
27+ LoadContent ( ) ;
28+ }
29+ }
30+ }
31+
32+ public bool ShowEntireFile
33+ {
34+ get => Preferences . Instance . UseFullTextDiff ;
35+ set
36+ {
37+ if ( value != Preferences . Instance . UseFullTextDiff )
38+ {
39+ Preferences . Instance . UseFullTextDiff = value ;
40+ OnPropertyChanged ( ) ;
41+
42+ if ( Content is ITextDiffContext ctx )
43+ {
44+ ctx . ResetScroll ( ) ;
45+ LoadContent ( ) ;
46+ }
47+ }
48+ }
49+ }
50+
51+ public bool UseBlockNavigation
52+ {
53+ get => Preferences . Instance . UseBlockNavigationInDiffView ;
54+ set
55+ {
56+ if ( value != Preferences . Instance . UseBlockNavigationInDiffView )
57+ {
58+ Preferences . Instance . UseBlockNavigationInDiffView = value ;
59+ OnPropertyChanged ( ) ;
60+ ( Content as ITextDiffContext ) ? . ResetBlockNavigation ( value ) ;
61+ }
62+ }
63+ }
64+
65+ public bool UseSideBySide
66+ {
67+ get => Preferences . Instance . UseSideBySideDiff ;
68+ set
69+ {
70+ if ( value != Preferences . Instance . UseSideBySideDiff )
71+ {
72+ Preferences . Instance . UseSideBySideDiff = value ;
73+ OnPropertyChanged ( ) ;
74+
75+ if ( Content is ITextDiffContext ctx && ctx . IsSideBySide ( ) != value )
76+ Content = ctx . SwitchMode ( ) ;
2877 }
2978 }
3079 }
@@ -72,33 +121,49 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
72121 else
73122 Title = $ "{ _option . OrgPath } → { _option . Path } ";
74123
75- LoadDiffContent ( ) ;
76- }
77-
78- public void ToggleFullTextDiff ( )
79- {
80- Preferences . Instance . UseFullTextDiff = ! Preferences . Instance . UseFullTextDiff ;
81- LoadDiffContent ( ) ;
124+ LoadContent ( ) ;
82125 }
83126
84127 public void IncrUnified ( )
85128 {
86129 UnifiedLines = _unifiedLines + 1 ;
87- LoadDiffContent ( ) ;
130+ LoadContent ( ) ;
88131 }
89132
90133 public void DecrUnified ( )
91134 {
92135 UnifiedLines = Math . Max ( 4 , _unifiedLines - 1 ) ;
93- LoadDiffContent ( ) ;
136+ LoadContent ( ) ;
94137 }
95138
96139 public void OpenExternalMergeTool ( )
97140 {
98141 new Commands . DiffTool ( _repo , _option ) . Open ( ) ;
99142 }
100143
101- private void LoadDiffContent ( )
144+ public void CheckSettings ( )
145+ {
146+ if ( Content is ITextDiffContext ctx )
147+ {
148+ if ( ( ShowEntireFile && _info . UnifiedLines != _entireFileLine ) ||
149+ ( ! ShowEntireFile && _info . UnifiedLines == _entireFileLine ) ||
150+ ( IgnoreWhitespace != _info . IgnoreWhitespace ) )
151+ {
152+ LoadContent ( ) ;
153+ return ;
154+ }
155+
156+ if ( ctx . IsSideBySide ( ) != UseSideBySide )
157+ {
158+ ctx = ctx . SwitchMode ( ) ;
159+ Content = ctx ;
160+ }
161+
162+ ctx . ResetBlockNavigation ( UseBlockNavigation ) ;
163+ }
164+ }
165+
166+ private void LoadContent ( )
102167 {
103168 if ( _option . Path . EndsWith ( '/' ) )
104169 {
@@ -109,7 +174,7 @@ private void LoadDiffContent()
109174
110175 Task . Run ( async ( ) =>
111176 {
112- var numLines = Preferences . Instance . UseFullTextDiff ? 999999999 : _unifiedLines ;
177+ var numLines = Preferences . Instance . UseFullTextDiff ? _entireFileLine : _unifiedLines ;
113178 var ignoreWhitespace = Preferences . Instance . IgnoreWhitespaceChangesInDiff ;
114179
115180 var latest = await new Commands . Diff ( _repo , _option , numLines , ignoreWhitespace )
@@ -228,12 +293,23 @@ private void LoadDiffContent()
228293
229294 Dispatcher . UIThread . Post ( ( ) =>
230295 {
231- if ( _content is Models . TextDiff old && rs is Models . TextDiff cur && old . File == cur . File )
232- cur . ScrollOffset = old . ScrollOffset ;
233-
234296 FileModeChange = latest . FileModeChange ;
235- Content = rs ;
236- IsTextDiff = rs is Models . TextDiff ;
297+
298+ if ( rs is Models . TextDiff cur )
299+ {
300+ IsTextDiff = true ;
301+
302+ var hasBlockNavigation = Preferences . Instance . UseBlockNavigationInDiffView ;
303+ if ( Preferences . Instance . UseSideBySideDiff )
304+ Content = new TwoSideTextDiff ( cur , hasBlockNavigation , _content as TwoSideTextDiff ) ;
305+ else
306+ Content = new CombinedTextDiff ( cur , hasBlockNavigation , _content as CombinedTextDiff ) ;
307+ }
308+ else
309+ {
310+ IsTextDiff = false ;
311+ Content = rs ;
312+ }
237313 } ) ;
238314 } ) ;
239315 }
@@ -279,6 +355,7 @@ public bool IsSame(Info other)
279355 }
280356 }
281357
358+ private readonly int _entireFileLine = 999999999 ;
282359 private readonly string _repo ;
283360 private readonly Models . DiffOption _option = null ;
284361 private string _fileModeChange = string . Empty ;
0 commit comments