From d09866e2c3abf2499d6bfa3aee92cb25ccc941de Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 17 Jul 2024 20:54:09 +0800 Subject: [PATCH 1/7] enhance: commit search (#268) * add `-i` parameter to ignore case while searching commit message * add `--branches --remotes` to search commits from all branches --- src/Commands/QueryCommits.cs | 26 ++++++++++++++++++-------- src/ViewModels/Repository.cs | 4 ++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Commands/QueryCommits.cs b/src/Commands/QueryCommits.cs index 66a1ee28..7d4b6991 100644 --- a/src/Commands/QueryCommits.cs +++ b/src/Commands/QueryCommits.cs @@ -14,20 +14,30 @@ namespace SourceGit.Commands _findFirstMerged = needFindHead; } - public QueryCommits(string repo, int maxCount, string messageFilter) + public QueryCommits(string repo, int maxCount, string messageFilter, bool isFile) { - var argsBuilder = new StringBuilder(); - var words = messageFilter.Split(new[] { ' ', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries); - foreach (var word in words) + string search; + if (isFile) { - var escaped = word.Trim().Replace("\"", "\\\"", StringComparison.Ordinal); - argsBuilder.Append($"--grep=\"{escaped}\" "); + search = $"-- \"{messageFilter}\""; } - argsBuilder.Append("--all-match"); + else + { + var argsBuilder = new StringBuilder(); + var words = messageFilter.Split(new[] { ' ', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries); + foreach (var word in words) + { + var escaped = word.Trim().Replace("\"", "\\\"", StringComparison.Ordinal); + argsBuilder.Append($"--grep=\"{escaped}\" "); + } + argsBuilder.Append("--all-match -i"); + search = argsBuilder.ToString(); + } + WorkingDirectory = repo; Context = repo; - Args = $"log -{maxCount} --date-order --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s " + argsBuilder.ToString(); + Args = $"log -{maxCount} --date-order --no-show-signature --decorate=full --pretty=format:%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%s --branches --remotes " + search; _findFirstMerged = false; } diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 36fd77d9..5f82953f 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -566,10 +566,10 @@ namespace SourceGit.ViewModels break; case 2: - visible = new Commands.QueryCommits(FullPath, 1000, _searchCommitFilter).Result(); + visible = new Commands.QueryCommits(FullPath, 1000, _searchCommitFilter, false).Result(); break; case 3: - visible = new Commands.QueryCommits(FullPath, $"-1000 -- \"{_searchCommitFilter}\"", false).Result(); + visible = new Commands.QueryCommits(FullPath, 1000, _searchCommitFilter, true).Result(); break; } From c0d0414ba2a128d5b0998a5de4452395d8d6646b Mon Sep 17 00:00:00 2001 From: Gadfly Date: Thu, 18 Jul 2024 09:28:05 +0800 Subject: [PATCH 2/7] ci: downgrade ci system --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 204c1afb..5d7acac8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: jobs: build-windows: name: Build Windows x64 - runs-on: windows-latest + runs-on: windows-2019 steps: - name: Checkout sources uses: actions/checkout@v4 @@ -30,7 +30,7 @@ jobs: path: publish build-macos-intel: name: Build macOS (Intel) - runs-on: macos-latest + runs-on: macos-13 steps: - name: Checkout sources uses: actions/checkout@v4 @@ -76,7 +76,7 @@ jobs: path: sourcegit.osx-arm64.tar build-linux: name: Build Linux - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: Checkout sources uses: actions/checkout@v4 From b2ed1b283ab6de678a1942fb954a293764b024c9 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 18 Jul 2024 10:17:40 +0800 Subject: [PATCH 3/7] enhance: only replace hunk data if needed --- src/Views/TextDiffView.axaml.cs | 52 ++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 9c03acad..0b09e3a4 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -29,6 +29,17 @@ namespace SourceGit.Views public double Height { get; set; } = 0.0; public int StartIdx { get; set; } = 0; public int EndIdx { get; set; } = 0; + + public bool ShouldReplace(TextViewHighlightChunk old) + { + if (old == null) + return true; + + return Math.Abs(Y - old.Y) > 0.001 || + Math.Abs(Height - old.Height) > 0.001 || + StartIdx != old.StartIdx || + EndIdx != old.EndIdx; + } } public class ThemedTextDiffPresenter : TextEditor @@ -214,6 +225,21 @@ namespace SourceGit.Views } } + protected void TrySetHighlightChunk(TextViewHighlightChunk chunk) + { + var old = HighlightChunk; + if (chunk == null) + { + if (old != null) + SetCurrentValue(HighlightChunkProperty, null); + + return; + } + + if (chunk.ShouldReplace(old)) + SetCurrentValue(HighlightChunkProperty, chunk); + } + protected (int, int) FindRangeByIndex(List lines, int lineIdx) { var startIdx = -1; @@ -598,7 +624,7 @@ namespace SourceGit.Views if (!string.IsNullOrEmpty(SelectedText)) { - SetCurrentValue(HighlightChunkProperty, null); + TrySetHighlightChunk(null); return; } @@ -622,14 +648,14 @@ namespace SourceGit.Views if (lineIdx == -1) { - SetCurrentValue(HighlightChunkProperty, null); + TrySetHighlightChunk(null); return; } var (startIdx, endIdx) = FindRangeByIndex(DiffData.Lines, lineIdx); if (startIdx == -1) { - SetCurrentValue(HighlightChunkProperty, null); + TrySetHighlightChunk(null); return; } @@ -643,14 +669,13 @@ namespace SourceGit.Views endLine.GetTextLineVisualYPosition(endLine.TextLines[^1], VisualYPosition.TextBottom) - view.VerticalOffset: view.Bounds.Height; - var hightlight = new TextViewHighlightChunk() + TrySetHighlightChunk(new TextViewHighlightChunk() { Y = rectStartY, Height = rectEndY - rectStartY, StartIdx = startIdx, EndIdx = endIdx, - }; - SetCurrentValue(HighlightChunkProperty, hightlight); + }); } } @@ -982,14 +1007,14 @@ namespace SourceGit.Views if (!string.IsNullOrEmpty(SelectedText)) { - SetCurrentValue(HighlightChunkProperty, null); + TrySetHighlightChunk(null); return; } var parentView = this.FindAncestorOfType(); if (parentView == null || parentView.DataContext == null) { - SetCurrentValue(HighlightChunkProperty, null); + TrySetHighlightChunk(null); return; } @@ -1015,14 +1040,14 @@ namespace SourceGit.Views if (lineIdx == -1) { - SetCurrentValue(HighlightChunkProperty, null); + TrySetHighlightChunk(null); return; } var (startIdx, endIdx) = FindRangeByIndex(lines, lineIdx); if (startIdx == -1) { - SetCurrentValue(HighlightChunkProperty, null); + TrySetHighlightChunk(null); return; } @@ -1036,14 +1061,13 @@ namespace SourceGit.Views endLine.GetTextLineVisualYPosition(endLine.TextLines[^1], VisualYPosition.TextBottom) - view.VerticalOffset : view.Bounds.Height; - var hightlight = new TextViewHighlightChunk() + TrySetHighlightChunk(new TextViewHighlightChunk() { Y = rectStartY, Height = rectEndY - rectStartY, StartIdx = textDiff.Lines.IndexOf(lines[startIdx]), - EndIdx = textDiff.Lines.IndexOf(lines[endIdx]), - }; - SetCurrentValue(HighlightChunkProperty, hightlight); + EndIdx = endIdx == lines.Count - 1 ? textDiff.Lines.Count - 1 : textDiff.Lines.IndexOf(lines[endIdx]), + }); } } From 14469b13990d9c6d93b447b4b967bd894167ba49 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 18 Jul 2024 10:46:39 +0800 Subject: [PATCH 4/7] theme: add `ThemeOverrides.OpacityForNotMergedCommits` to customize the opacity of commits that not belongs (haven't been merged) to current branch in histories (#268) --- src/App.axaml.cs | 2 ++ src/Converters/BoolConverters.cs | 7 ------- src/Models/Commit.cs | 10 ++++++++++ src/Models/ThemeOverrides.cs | 1 + src/Views/Histories.axaml | 18 +++++++++--------- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 67bd3aad..7abf8293 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -188,6 +188,8 @@ namespace SourceGit else Models.CommitGraph.SetDefaultPens(overrides.GraphPenThickness); + Models.Commit.OpacityForNotMerged = overrides.OpacityForNotMergedCommits; + app.Resources.MergedDictionaries.Add(resDic); app._themeOverrides = resDic; } diff --git a/src/Converters/BoolConverters.cs b/src/Converters/BoolConverters.cs index 2eb8c60a..2d738700 100644 --- a/src/Converters/BoolConverters.cs +++ b/src/Converters/BoolConverters.cs @@ -1,5 +1,4 @@ using Avalonia.Data.Converters; -using Avalonia.Media; namespace SourceGit.Converters { @@ -7,11 +6,5 @@ namespace SourceGit.Converters { public static readonly FuncValueConverter ToPageTabWidth = new FuncValueConverter(x => x ? 200 : double.NaN); - - public static readonly FuncValueConverter HalfIfFalse = - new FuncValueConverter(x => x ? 1 : 0.5); - - public static readonly FuncValueConverter BoldIfTrue = - new FuncValueConverter(x => x ? FontWeight.Bold : FontWeight.Regular); } } diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index 30c2c499..1137ad0c 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -2,11 +2,18 @@ using System.Collections.Generic; using Avalonia; +using Avalonia.Media; namespace SourceGit.Models { public class Commit { + public static double OpacityForNotMerged + { + get; + set; + } = 0.5; + public string SHA { get; set; } = string.Empty; public User Author { get; set; } = User.Invalid; public ulong AuthorTime { get; set; } = 0; @@ -25,5 +32,8 @@ namespace SourceGit.Models public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime; public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null; + + public double Opacity => IsMerged ? 1 : OpacityForNotMerged; + public FontWeight FontWeight => IsCurrentHead ? FontWeight.Bold : FontWeight.Regular; } } diff --git a/src/Models/ThemeOverrides.cs b/src/Models/ThemeOverrides.cs index e14b1f1a..ccd9f57e 100644 --- a/src/Models/ThemeOverrides.cs +++ b/src/Models/ThemeOverrides.cs @@ -8,6 +8,7 @@ namespace SourceGit.Models { public Dictionary BasicColors { get; set; } = new Dictionary(); public double GraphPenThickness { get; set; } = 2; + public double OpacityForNotMergedCommits { get; set; } = 0.5; public List GraphColors { get; set; } = new List(); } } diff --git a/src/Views/Histories.axaml b/src/Views/Histories.axaml index 6e89a036..1a74a08a 100644 --- a/src/Views/Histories.axaml +++ b/src/Views/Histories.axaml @@ -103,8 +103,8 @@ + Opacity="{Binding Opacity}" + FontWeight="{Binding FontWeight}"/> @@ -124,13 +124,13 @@ VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}" - Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"/> + Opacity="{Binding Opacity}"/> + Opacity="{Binding Opacity}" + FontWeight="{Binding FontWeight}"/> @@ -147,8 +147,8 @@ Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Margin="8,0" HorizontalAlignment="Center" - Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}" - FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/> + Opacity="{Binding Opacity}" + FontWeight="{Binding FontWeight}"/> @@ -169,8 +169,8 @@ From e64026d44c6034c63b894bf74380e18761348da7 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 18 Jul 2024 11:26:47 +0800 Subject: [PATCH 5/7] fix: `MakeSelection` should not use `UseSideBySideDiff` directly --- src/Views/TextDiffView.axaml.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 0b09e3a4..0b7a6071 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -1162,7 +1162,7 @@ namespace SourceGit.Views if (UseSideBySideDiff) (startLine, endLine) = GetUnifiedRange(diff, startLine, endLine, isOldSide); - var selection = MakeSelection(diff, startLine, endLine, isOldSide); + var selection = MakeSelection(diff, startLine, endLine, !UseSideBySideDiff, isOldSide); if (!selection.HasChanges) return; @@ -1429,7 +1429,7 @@ namespace SourceGit.Views if (change == null) return; - var selection = MakeSelection(diff, chunk.StartIdx + 1, chunk.EndIdx + 1, false); + var selection = MakeSelection(diff, chunk.StartIdx + 1, chunk.EndIdx + 1, true, false); if (!selection.HasChanges) return; @@ -1487,7 +1487,7 @@ namespace SourceGit.Views if (change == null) return; - var selection = MakeSelection(diff, chunk.StartIdx + 1, chunk.EndIdx + 1, false); + var selection = MakeSelection(diff, chunk.StartIdx + 1, chunk.EndIdx + 1, true, false); if (!selection.HasChanges) return; @@ -1543,7 +1543,7 @@ namespace SourceGit.Views if (change == null) return; - var selection = MakeSelection(diff, chunk.StartIdx + 1, chunk.EndIdx + 1, false); + var selection = MakeSelection(diff, chunk.StartIdx + 1, chunk.EndIdx + 1, true, false); if (!selection.HasChanges) return; @@ -1632,7 +1632,7 @@ namespace SourceGit.Views return (startLine, endLine); } - private Models.TextDiffSelection MakeSelection(Models.TextDiff diff, int startLine, int endLine, bool isOldSide) + private Models.TextDiffSelection MakeSelection(Models.TextDiff diff, int startLine, int endLine, bool combined, bool isOldSide) { var rs = new Models.TextDiffSelection(); rs.StartLine = startLine; @@ -1658,7 +1658,7 @@ namespace SourceGit.Views var line = diff.Lines[i]; if (line.Type == Models.TextDiffLineType.Added) { - if (!UseSideBySideDiff) + if (combined) { rs.HasChanges = true; break; @@ -1674,7 +1674,7 @@ namespace SourceGit.Views } else if (line.Type == Models.TextDiffLineType.Deleted) { - if (!UseSideBySideDiff) + if (combined) { rs.HasChanges = true; break; From dbc95e72091187dadf8167a9e6409a5154141799 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 18 Jul 2024 11:40:56 +0800 Subject: [PATCH 6/7] refactor: move some method from view to its data source class --- src/Models/DiffResult.cs | 80 +++++++++++++++++- src/ViewModels/TwoSideTextDiff.cs | 44 +++++++++- src/Views/TextDiffView.axaml.cs | 129 ++---------------------------- 3 files changed, 126 insertions(+), 127 deletions(-) diff --git a/src/Models/DiffResult.cs b/src/Models/DiffResult.cs index 1c270470..0779029f 100644 --- a/src/Models/DiffResult.cs +++ b/src/Models/DiffResult.cs @@ -69,6 +69,80 @@ namespace SourceGit.Models public string Repo { get; set; } = null; public DiffOption Option { get; set; } = null; + public TextDiffSelection MakeSelection(int startLine, int endLine, bool isSideBySide, bool isOldSide) + { + var rs = new TextDiffSelection(); + rs.StartLine = startLine; + rs.EndLine = endLine; + + for (int i = 0; i < startLine - 1; i++) + { + var line = Lines[i]; + if (line.Type == TextDiffLineType.Added) + { + rs.HasLeftChanges = true; + rs.IgnoredAdds++; + } + else if (line.Type == TextDiffLineType.Deleted) + { + rs.HasLeftChanges = true; + rs.IgnoredDeletes++; + } + } + + for (int i = startLine - 1; i < endLine; i++) + { + var line = Lines[i]; + if (line.Type == TextDiffLineType.Added) + { + if (!isSideBySide) + { + rs.HasChanges = true; + break; + } + else if (isOldSide) + { + rs.HasLeftChanges = true; + } + else + { + rs.HasChanges = true; + } + } + else if (line.Type == TextDiffLineType.Deleted) + { + if (!isSideBySide) + { + rs.HasChanges = true; + break; + } + else if (isOldSide) + { + rs.HasChanges = true; + } + else + { + rs.HasLeftChanges = true; + } + } + } + + if (!rs.HasLeftChanges) + { + for (int i = endLine; i < Lines.Count; i++) + { + var line = Lines[i]; + if (line.Type == TextDiffLineType.Added || line.Type == TextDiffLineType.Deleted) + { + rs.HasLeftChanges = true; + break; + } + } + } + + return rs; + } + public void GenerateNewPatchFromSelection(Change change, string fileBlobGuid, TextDiffSelection selection, bool revert, string output) { var isTracked = !string.IsNullOrEmpty(fileBlobGuid); @@ -392,9 +466,6 @@ namespace SourceGit.Models System.IO.File.WriteAllText(output, builder.ToString()); } - [GeneratedRegex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@")] - private static partial Regex REG_INDICATOR(); - private bool ProcessIndicatorForPatch(StringBuilder builder, TextDiffLine indicator, int idx, int start, int end, int ignoreRemoves, int ignoreAdds, bool revert, bool tailed) { var match = REG_INDICATOR().Match(indicator.Content); @@ -554,6 +625,9 @@ namespace SourceGit.Models builder.Append($"\n@@ -{oldStart},{oldCount} +{newStart},{newCount} @@"); return true; } + + [GeneratedRegex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@")] + private static partial Regex REG_INDICATOR(); } public class LFSDiff diff --git a/src/ViewModels/TwoSideTextDiff.cs b/src/ViewModels/TwoSideTextDiff.cs index 59e70a88..d4d69059 100644 --- a/src/ViewModels/TwoSideTextDiff.cs +++ b/src/ViewModels/TwoSideTextDiff.cs @@ -1,5 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; + using Avalonia; + using CommunityToolkit.Mvvm.ComponentModel; namespace SourceGit.ViewModels @@ -53,6 +56,45 @@ namespace SourceGit.ViewModels _syncScrollOffset = previous._syncScrollOffset; } + public void ConvertsToCombinedRange(Models.TextDiff combined, ref int startLine, ref int endLine, bool isOldSide) + { + endLine = Math.Min(endLine, combined.Lines.Count); + + var oneSide = isOldSide ? Old : New; + var firstContentLine = -1; + for (int i = startLine - 1; i < endLine; i++) + { + var line = oneSide[i]; + if (line.Type != Models.TextDiffLineType.None) + { + firstContentLine = i; + break; + } + } + + if (firstContentLine < 0) + return; + + var endContentLine = -1; + for (int i = Math.Min(endLine - 1, oneSide.Count - 1); i >= startLine - 1; i--) + { + var line = oneSide[i]; + if (line.Type != Models.TextDiffLineType.None) + { + endContentLine = i; + break; + } + } + + if (endContentLine < 0) + return; + + var firstContent = oneSide[firstContentLine]; + var endContent = oneSide[endContentLine]; + startLine = combined.Lines.IndexOf(firstContent) + 1; + endLine = combined.Lines.IndexOf(endContent) + 1; + } + private void FillEmptyLines() { if (Old.Count < New.Count) diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 0b7a6071..6f68fad4 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -1159,10 +1159,10 @@ namespace SourceGit.Views if (startLine > endLine) (startLine, endLine) = (endLine, startLine); - if (UseSideBySideDiff) - (startLine, endLine) = GetUnifiedRange(diff, startLine, endLine, isOldSide); + if (Editor.Content is ViewModels.TwoSideTextDiff twoSides) + twoSides.ConvertsToCombinedRange(diff, ref startLine, ref endLine, isOldSide); - var selection = MakeSelection(diff, startLine, endLine, !UseSideBySideDiff, isOldSide); + var selection = diff.MakeSelection(startLine, endLine, UseSideBySideDiff, isOldSide); if (!selection.HasChanges) return; @@ -1429,7 +1429,7 @@ namespace SourceGit.Views if (change == null) return; - var selection = MakeSelection(diff, chunk.StartIdx + 1, chunk.EndIdx + 1, true, false); + var selection = diff.MakeSelection(chunk.StartIdx + 1, chunk.EndIdx + 1, false, false); if (!selection.HasChanges) return; @@ -1487,7 +1487,7 @@ namespace SourceGit.Views if (change == null) return; - var selection = MakeSelection(diff, chunk.StartIdx + 1, chunk.EndIdx + 1, true, false); + var selection = diff.MakeSelection(chunk.StartIdx + 1, chunk.EndIdx + 1, false, false); if (!selection.HasChanges) return; @@ -1543,7 +1543,7 @@ namespace SourceGit.Views if (change == null) return; - var selection = MakeSelection(diff, chunk.StartIdx + 1, chunk.EndIdx + 1, true, false); + var selection = diff.MakeSelection(chunk.StartIdx + 1, chunk.EndIdx + 1, false, false); if (!selection.HasChanges) return; @@ -1588,122 +1588,5 @@ namespace SourceGit.Views repo.SetWatcherEnabled(true); } } - - private (int, int) GetUnifiedRange(Models.TextDiff diff, int startLine, int endLine, bool isOldSide) - { - endLine = Math.Min(endLine, diff.Lines.Count); - if (Editor.Content is ViewModels.TwoSideTextDiff twoSides) - { - var target = isOldSide ? twoSides.Old : twoSides.New; - var firstContentLine = -1; - for (int i = startLine - 1; i < endLine; i++) - { - var line = target[i]; - if (line.Type != Models.TextDiffLineType.None) - { - firstContentLine = i; - break; - } - } - - if (firstContentLine < 0) - return (-1, -1); - - var endContentLine = -1; - for (int i = Math.Min(endLine - 1, target.Count - 1); i >= startLine - 1; i--) - { - var line = target[i]; - if (line.Type != Models.TextDiffLineType.None) - { - endContentLine = i; - break; - } - } - - if (endContentLine < 0) - return (-1, -1); - - var firstContent = target[firstContentLine]; - var endContent = target[endContentLine]; - startLine = diff.Lines.IndexOf(firstContent) + 1; - endLine = diff.Lines.IndexOf(endContent) + 1; - } - - return (startLine, endLine); - } - - private Models.TextDiffSelection MakeSelection(Models.TextDiff diff, int startLine, int endLine, bool combined, bool isOldSide) - { - var rs = new Models.TextDiffSelection(); - rs.StartLine = startLine; - rs.EndLine = endLine; - - for (int i = 0; i < startLine - 1; i++) - { - var line = diff.Lines[i]; - if (line.Type == Models.TextDiffLineType.Added) - { - rs.HasLeftChanges = true; - rs.IgnoredAdds++; - } - else if (line.Type == Models.TextDiffLineType.Deleted) - { - rs.HasLeftChanges = true; - rs.IgnoredDeletes++; - } - } - - for (int i = startLine - 1; i < endLine; i++) - { - var line = diff.Lines[i]; - if (line.Type == Models.TextDiffLineType.Added) - { - if (combined) - { - rs.HasChanges = true; - break; - } - else if (isOldSide) - { - rs.HasLeftChanges = true; - } - else - { - rs.HasChanges = true; - } - } - else if (line.Type == Models.TextDiffLineType.Deleted) - { - if (combined) - { - rs.HasChanges = true; - break; - } - else if (isOldSide) - { - rs.HasChanges = true; - } - else - { - rs.HasLeftChanges = true; - } - } - } - - if (!rs.HasLeftChanges) - { - for (int i = endLine; i < diff.Lines.Count; i++) - { - var line = diff.Lines[i]; - if (line.Type == Models.TextDiffLineType.Added || line.Type == Models.TextDiffLineType.Deleted) - { - rs.HasLeftChanges = true; - break; - } - } - } - - return rs; - } } } From 42f8e419858c0c75fbdbaa2ca2e4bf012519a3bb Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 18 Jul 2024 12:13:19 +0800 Subject: [PATCH 7/7] ux: lower background opacity for selected hunk --- src/Views/TextDiffView.axaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 6f68fad4..4f904f8a 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -169,11 +169,11 @@ namespace SourceGit.Views return; var color = (Color)this.FindResource("SystemAccentColor"); - var brush = new SolidColorBrush(color, 0.5); + var brush = new SolidColorBrush(color, 0.1); var pen = new Pen(color.ToUInt32()); var x = ((Point)view.TranslatePoint(new Point(0, 0), this)).X; - var rect = new Rect(x - 4, highlightChunk.Y, view.Bounds.Width + 8, highlightChunk.Height); + var rect = new Rect(x - 4, highlightChunk.Y, view.Bounds.Width + 7, highlightChunk.Height); context.DrawRectangle(brush, null, rect); context.DrawLine(pen, rect.TopLeft, rect.TopRight);