Skip to content

Commit 9ba0b59

Browse files
committed
enhance: remember the last state of Ignore Whitespace Change and EOF in text diff view (#1198)
Signed-off-by: leo <longshuang@msn.cn>
1 parent cf763b4 commit 9ba0b59

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/ViewModels/DiffContext.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ public string Title
1919

2020
public bool IgnoreWhitespace
2121
{
22-
get => _ignoreWhitespace;
22+
get => Preferences.Instance.IgnoreWhitespaceChangesInDiff;
2323
set
2424
{
25-
if (SetProperty(ref _ignoreWhitespace, value))
25+
if (value != Preferences.Instance.IgnoreWhitespaceChangesInDiff)
26+
{
27+
Preferences.Instance.IgnoreWhitespaceChangesInDiff = value;
28+
OnPropertyChanged();
2629
LoadDiffContent();
30+
}
2731
}
2832
}
2933

@@ -62,7 +66,6 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
6266
_content = previous._content;
6367
_fileModeChange = previous._fileModeChange;
6468
_unifiedLines = previous._unifiedLines;
65-
_ignoreWhitespace = previous._ignoreWhitespace;
6669
_info = previous._info;
6770
}
6871

@@ -114,8 +117,9 @@ private void LoadDiffContent()
114117
// There is no way to tell a git-diff to use "ALL lines of context",
115118
// so instead we set a very high number for the "lines of context" parameter.
116119
var numLines = Preferences.Instance.UseFullTextDiff ? 999999999 : _unifiedLines;
117-
var latest = new Commands.Diff(_repo, _option, numLines, _ignoreWhitespace).Result();
118-
var info = new Info(_option, numLines, _ignoreWhitespace, latest);
120+
var ignoreWS = Preferences.Instance.IgnoreWhitespaceChangesInDiff;
121+
var latest = new Commands.Diff(_repo, _option, numLines, ignoreWS).Result();
122+
var info = new Info(_option, numLines, ignoreWS, latest);
119123
if (_info != null && info.IsSame(_info))
120124
return;
121125

@@ -287,7 +291,6 @@ public bool IsSame(Info other)
287291
private string _fileModeChange = string.Empty;
288292
private int _unifiedLines = 4;
289293
private bool _isTextDiff = false;
290-
private bool _ignoreWhitespace = false;
291294
private object _content = null;
292295
private Info _info = null;
293296
}

src/ViewModels/Preferences.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ public bool UseSyntaxHighlighting
212212
set => SetProperty(ref _useSyntaxHighlighting, value);
213213
}
214214

215+
public bool IgnoreWhitespaceChangesInDiff
216+
{
217+
get => _ignoreWhitespaceChangesInDiff;
218+
set => SetProperty(ref _ignoreWhitespaceChangesInDiff, value);
219+
}
220+
215221
public bool EnableDiffViewWordWrap
216222
{
217223
get => _enableDiffViewWordWrap;
@@ -658,6 +664,7 @@ private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)
658664
private bool _useTwoColumnsLayoutInHistories = false;
659665
private bool _displayTimeAsPeriodInHistories = false;
660666
private bool _useSideBySideDiff = false;
667+
private bool _ignoreWhitespaceChangesInDiff = false;
661668
private bool _useSyntaxHighlighting = false;
662669
private bool _enableDiffViewWordWrap = false;
663670
private bool _showHiddenSymbolsInDiffView = false;

src/Views/CommitMessageTextBox.axaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@
6666
CornerRadius="0,0,4,4">
6767
<Grid ColumnDefinitions="*,Auto,Auto" Margin="0,4">
6868
<StackPanel Grid.Column="0"
69-
Margin="8,0"
7069
VerticalAlignment="Center"
7170
Orientation="Horizontal">
72-
<TextBlock Classes="info_label" FontSize="13" Text="{DynamicResource Text.CommitMessageTextBox.SubjectCount}"/>
71+
<TextBlock Classes="info_label" FontSize="13" HorizontalAlignment="Left" Margin="4,0,0,0" Text="{DynamicResource Text.CommitMessageTextBox.SubjectCount}"/>
7372
<TextBlock Classes="primary" Margin="8,0,0,0" FontSize="11" Text="{Binding #ThisControl.Subject.Length}" IsVisible="{Binding #ThisControl.Subject.Length, Converter={x:Static c:IntConverters.IsSubjectLengthGood}}" VerticalAlignment="Center"/>
7473
<TextBlock Classes="primary" Margin="8,0,0,0" FontSize="11" Foreground="DarkGoldenrod" Text="{Binding #ThisControl.Subject.Length}" IsVisible="{Binding #ThisControl.Subject.Length, Converter={x:Static c:IntConverters.IsSubjectLengthBad}}" VerticalAlignment="Center"/>
7574
<TextBlock Classes="primary" FontSize="11" Text="/" VerticalAlignment="Center"/>

0 commit comments

Comments
 (0)