Skip to content

Conversation

gadfly3173
Copy link
Contributor

Fixed the crash when the font is ,SomeFont.

Situation encountered:
When I added Noto Color Emoji, I wrote it at the beginning of the default font. In the TextBox, it was Noto Color Emoji, HarmonyOS Sans SC. Then I found that the digital font became emoji, so I deleted the content before , and the whole app crashed.

@love-linger
Copy link
Collaborator

I suggest you to move your code into SourceGit.ViewModels.Preferences.FixFontFamilyName

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();
}

@love-linger love-linger self-assigned this Mar 13, 2025
@love-linger love-linger added the bug Something isn't working label Mar 13, 2025
@gadfly3173
Copy link
Contributor Author

gadfly3173 commented Mar 13, 2025

If move code into SourceGit.ViewModels.Preferences.FixFontFamilyName , It would be unable to type , at the end of the font string, I think with the new code, FixFontFamilyName could be removed. Currently, remove the spaces after the font string looks strange.

_sourcegit_20250313150319.mp4

@love-linger
Copy link
Collaborator

If we do not remove the whitespace char at the end of a font name, SourceGit will also crashed.

Try Microsoft YaHei , Consolas

@love-linger
Copy link
Collaborator

I'll merge this PR first, and add some modifications.

@love-linger love-linger merged commit b9b684a into sourcegit-scm:develop Mar 13, 2025
13 checks passed
@gadfly3173
Copy link
Contributor Author

gadfly3173 commented Mar 13, 2025

var trimmed = part.Trim();

my code trimmed every font

@gadfly3173 gadfly3173 deleted the fix/font branch March 13, 2025 07:08
love-linger added a commit that referenced this pull request Mar 13, 2025
- Remove `SourceGit.ViewModels.Preference.FixFontFamilyName` (it is not necessary any more)
- Use `string.Join` instead of `StringBuilder` to make the logic more clear

Signed-off-by: leo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants