refactor: improve diff handling for EOL changes and enhance text diff… (#1177)

* refactor: improve diff handling for EOL changes and enhance text diff display

- Updated `Diff.cs` to streamline whitespace handling in diff arguments.
- Enhanced `DiffContext.cs` to check for EOL changes when old and new hashes differ, creating a text diff if necessary.
- Added support for showing end-of-line symbols in `TextDiffView.axaml.cs` options.

* localization: update translations to include EOF handling in ignore whitespace messages

- Modified the ignore whitespace text in multiple language files to specify that EOF changes are also ignored.
- Ensured consistency across all localization files for the patch application feature.

* revert: Typo in DiffResult comment

* revert: update diff arguments to ignore CR at EOL in whitespace handling (like before changes)

* revert: update translations to remove EOF references in Text.Apply.IgnoreWS and fixed typo in Text.Diff.IgnoreWhitespace (EOF => EOL)

---------

Co-authored-by: mpagani <massimo.pagani@unitec-group.com>
This commit is contained in:
Massimo 2025-04-14 09:18:45 +02:00 committed by GitHub
parent e7f0217a7b
commit 81820e7034
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 57 additions and 13 deletions

View file

@ -207,7 +207,50 @@ namespace SourceGit.ViewModels
}
else
{
rs = new Models.NoOrEOLChange();
// Check if old and new hashes differ but no text changes found
if (!string.IsNullOrEmpty(latest.OldHash) &&
!string.IsNullOrEmpty(latest.NewHash) &&
latest.OldHash != latest.NewHash)
{
// If hashes differ but no text diff found, it's likely an EOL change
// Create a text diff to show the file content
var textDiff = new Models.TextDiff()
{
Repo = _repo,
Option = _option,
File = _option.Path
};
// Query the file content to show
var fileContent = Commands.QueryFileContent.Run(_repo, "HEAD", _option.Path);
using var reader = new StreamReader(fileContent);
var line = string.Empty;
int lineNumber = 1;
while ((line = reader.ReadLine()) != null)
{
textDiff.Lines.Add(new Models.TextDiffLine(
Models.TextDiffLineType.Normal,
line,
lineNumber,
lineNumber));
lineNumber++;
}
if (textDiff.Lines.Count > 0)
{
textDiff.MaxLineNumber = lineNumber - 1;
rs = textDiff;
}
else
{
rs = new Models.NoOrEOLChange();
}
}
else
{
rs = new Models.NoOrEOLChange();
}
}
Dispatcher.UIThread.Post(() =>