From b9b684a83d58740d2bd802e08ad83746fcb97359 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Thu, 13 Mar 2025 15:05:30 +0800 Subject: [PATCH] fix: improve font string processing in SetFonts method (#1092) --- src/App.axaml.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 25e32323..504981f7 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -181,6 +181,9 @@ namespace SourceGit app._fontsOverrides = null; } + defaultFont = ProcessFontString(defaultFont); + monospaceFont = ProcessFontString(monospaceFont); + var resDic = new ResourceDictionary(); if (!string.IsNullOrEmpty(defaultFont)) resDic.Add("Fonts.Default", new FontFamily(defaultFont)); @@ -437,6 +440,28 @@ namespace SourceGit return true; } + private static string ProcessFontString(string input) + { + if (string.IsNullOrEmpty(input)) return string.Empty; + + var parts = input.Split(','); + var result = new StringBuilder(); + var isFirst = true; + + foreach (var part in parts) + { + var trimmed = part.Trim(); + if (!string.IsNullOrEmpty(trimmed)) + { + if (!isFirst) result.Append(','); + result.Append(trimmed); + isFirst = false; + } + } + + return result.ToString(); + } + private bool TryLaunchAsCoreEditor(IClassicDesktopStyleApplicationLifetime desktop) { var args = desktop.Args;