diff --git a/src/Commands/CompareRevisions.cs b/src/Commands/CompareRevisions.cs index 7b4a496d..c88e087a 100644 --- a/src/Commands/CompareRevisions.cs +++ b/src/Commands/CompareRevisions.cs @@ -39,7 +39,7 @@ namespace SourceGit.Commands foreach (var line in lines) ParseLine(line); - _changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal)); + _changes.Sort((l, r) => Models.NumericSort.Compare(l.Path, r.Path)); return _changes; } diff --git a/src/Models/NumericSort.cs b/src/Models/NumericSort.cs index ed5002e6..3bb69fe2 100644 --- a/src/Models/NumericSort.cs +++ b/src/Models/NumericSort.cs @@ -1,4 +1,7 @@ -namespace SourceGit.Models +using System; +using System.Globalization; + +namespace SourceGit.Models { public static class NumericSort { @@ -23,7 +26,7 @@ bool isDigit1 = char.IsDigit(c1); bool isDigit2 = char.IsDigit(c2); if (isDigit1 != isDigit2) - return c1.CompareTo(c2); + return char.ToUpper(c1, CultureInfo.CurrentCulture).CompareTo(char.ToUpper(c2, CultureInfo.CurrentCulture)); do { @@ -55,7 +58,7 @@ if (isDigit1) result = loc1 == loc2 ? string.CompareOrdinal(sub1, sub2) : loc1 - loc2; else - result = string.CompareOrdinal(sub1, sub2); + result = string.Compare(sub1, sub2, StringComparison.OrdinalIgnoreCase); if (result != 0) return result; diff --git a/src/ViewModels/Preferences.cs b/src/ViewModels/Preferences.cs index e41e046e..665b7604 100644 --- a/src/ViewModels/Preferences.cs +++ b/src/ViewModels/Preferences.cs @@ -449,7 +449,7 @@ namespace SourceGit.ViewModels if (l.IsRepository != r.IsRepository) return l.IsRepository ? 1 : -1; - return string.Compare(l.Name, r.Name, StringComparison.Ordinal); + return Models.NumericSort.Compare(l.Name, r.Name); }); } diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index af72e72a..44fbffc5 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1275,6 +1275,7 @@ namespace SourceGit.ViewModels if (_workingCopy == null) return; + changes.Sort((l, r) => Models.NumericSort.Compare(l.Path, r.Path)); _workingCopy.SetData(changes); Dispatcher.UIThread.Invoke(() => diff --git a/src/ViewModels/StashesPage.cs b/src/ViewModels/StashesPage.cs index dec8ea6b..eba8ac28 100644 --- a/src/ViewModels/StashesPage.cs +++ b/src/ViewModels/StashesPage.cs @@ -71,7 +71,7 @@ namespace SourceGit.ViewModels changes.Add(c); if (needSort) - changes.Sort((l, r) => string.Compare(l.Path, r.Path, StringComparison.Ordinal)); + changes.Sort((l, r) => Models.NumericSort.Compare(l.Path, r.Path)); } Dispatcher.UIThread.Invoke(() => diff --git a/src/Views/RevisionFileTreeView.axaml.cs b/src/Views/RevisionFileTreeView.axaml.cs index 410f747e..98f32c25 100644 --- a/src/Views/RevisionFileTreeView.axaml.cs +++ b/src/Views/RevisionFileTreeView.axaml.cs @@ -270,12 +270,7 @@ namespace SourceGit.Views foreach (var obj in objects) _tree.Add(new ViewModels.RevisionFileTreeNode { Backend = obj }); - _tree.Sort((l, r) => - { - if (l.IsFolder == r.IsFolder) - return string.Compare(l.Name, r.Name, StringComparison.Ordinal); - return l.IsFolder ? -1 : 1; - }); + SortNodes(_tree); var topTree = new List(); MakeRows(topTree, _tree, 0); @@ -341,13 +336,7 @@ namespace SourceGit.Views foreach (var obj in objects) node.Children.Add(new ViewModels.RevisionFileTreeNode() { Backend = obj }); - node.Children.Sort((l, r) => - { - if (l.IsFolder == r.IsFolder) - return Models.NumericSort.Compare(l.Name, r.Name); - return l.IsFolder ? -1 : 1; - }); - + SortNodes(node.Children); return node.Children; } @@ -365,6 +354,16 @@ namespace SourceGit.Views } } + private void SortNodes(List nodes) + { + nodes.Sort((l, r) => + { + if (l.IsFolder == r.IsFolder) + return Models.NumericSort.Compare(l.Name, r.Name); + return l.IsFolder ? -1 : 1; + }); + } + private List _tree = []; private AvaloniaList _rows = []; private bool _disableSelectionChangingEvent = false;