diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 504981f7..79eeda4e 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -181,8 +181,8 @@ namespace SourceGit app._fontsOverrides = null; } - defaultFont = ProcessFontString(defaultFont); - monospaceFont = ProcessFontString(monospaceFont); + defaultFont = FixFontFamilyName(defaultFont); + monospaceFont = FixFontFamilyName(monospaceFont); var resDic = new ResourceDictionary(); if (!string.IsNullOrEmpty(defaultFont)) @@ -440,26 +440,22 @@ namespace SourceGit return true; } - private static string ProcessFontString(string input) + private static string FixFontFamilyName(string input) { - if (string.IsNullOrEmpty(input)) return string.Empty; + if (string.IsNullOrEmpty(input)) + return string.Empty; var parts = input.Split(','); - var result = new StringBuilder(); - var isFirst = true; + var trimmed = new List(); foreach (var part in parts) { - var trimmed = part.Trim(); - if (!string.IsNullOrEmpty(trimmed)) - { - if (!isFirst) result.Append(','); - result.Append(trimmed); - isFirst = false; - } + var t = part.Trim(); + if (!string.IsNullOrEmpty(t)) + trimmed.Add(t); } - return result.ToString(); + return trimmed.Count > 0 ? string.Join(',', trimmed) : string.Empty; } private bool TryLaunchAsCoreEditor(IClassicDesktopStyleApplicationLifetime desktop) diff --git a/src/ViewModels/Preferences.cs b/src/ViewModels/Preferences.cs index dae90517..0b1d841e 100644 --- a/src/ViewModels/Preferences.cs +++ b/src/ViewModels/Preferences.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Text; using System.Text.Json; using System.Text.Json.Serialization; using Avalonia.Collections; @@ -66,9 +65,8 @@ namespace SourceGit.ViewModels get => _defaultFontFamily; set { - var name = FixFontFamilyName(value); - if (SetProperty(ref _defaultFontFamily, name) && !_isLoading) - App.SetFonts(_defaultFontFamily, _monospaceFontFamily, _onlyUseMonoFontInEditor); + if (SetProperty(ref _defaultFontFamily, value) && !_isLoading) + App.SetFonts(value, _monospaceFontFamily, _onlyUseMonoFontInEditor); } } @@ -77,9 +75,8 @@ namespace SourceGit.ViewModels get => _monospaceFontFamily; set { - var name = FixFontFamilyName(value); - if (SetProperty(ref _monospaceFontFamily, name) && !_isLoading) - App.SetFonts(_defaultFontFamily, _monospaceFontFamily, _onlyUseMonoFontInEditor); + if (SetProperty(ref _monospaceFontFamily, value) && !_isLoading) + App.SetFonts(_defaultFontFamily, value, _onlyUseMonoFontInEditor); } } @@ -620,35 +617,6 @@ namespace SourceGit.ViewModels return changed; } - private string FixFontFamilyName(string name) - { - var trimmed = name.Trim(); - if (string.IsNullOrEmpty(trimmed)) - return string.Empty; - - var builder = new StringBuilder(); - var lastIsSpace = false; - for (int i = 0; i < trimmed.Length; i++) - { - var c = trimmed[i]; - if (char.IsWhiteSpace(c)) - { - if (lastIsSpace) - continue; - - lastIsSpace = true; - } - else - { - lastIsSpace = false; - } - - builder.Append(c); - } - - return builder.ToString(); - } - private static Preferences _instance = null; private static bool _isLoading = false;