mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-25 21:07:20 -08:00
fix: avoid crash if fontfamily contains consecutive whitespace (#799)
This commit is contained in:
parent
0a486a90d9
commit
33ef9a612d
1 changed files with 34 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using Avalonia.Collections;
|
using Avalonia.Collections;
|
||||||
|
@ -65,8 +66,8 @@ namespace SourceGit.ViewModels
|
||||||
get => _defaultFontFamily;
|
get => _defaultFontFamily;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
var trimmed = value.Trim();
|
var name = FixFontFamilyName(value);
|
||||||
if (SetProperty(ref _defaultFontFamily, trimmed) && !_isLoading)
|
if (SetProperty(ref _defaultFontFamily, name) && !_isLoading)
|
||||||
App.SetFonts(_defaultFontFamily, _monospaceFontFamily, _onlyUseMonoFontInEditor);
|
App.SetFonts(_defaultFontFamily, _monospaceFontFamily, _onlyUseMonoFontInEditor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,8 +77,8 @@ namespace SourceGit.ViewModels
|
||||||
get => _monospaceFontFamily;
|
get => _monospaceFontFamily;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
var trimmed = value.Trim();
|
var name = FixFontFamilyName(value);
|
||||||
if (SetProperty(ref _monospaceFontFamily, trimmed) && !_isLoading)
|
if (SetProperty(ref _monospaceFontFamily, name) && !_isLoading)
|
||||||
App.SetFonts(_defaultFontFamily, _monospaceFontFamily, _onlyUseMonoFontInEditor);
|
App.SetFonts(_defaultFontFamily, _monospaceFontFamily, _onlyUseMonoFontInEditor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -588,6 +589,35 @@ namespace SourceGit.ViewModels
|
||||||
return changed;
|
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 Preference _instance = null;
|
private static Preference _instance = null;
|
||||||
private static bool _isLoading = false;
|
private static bool _isLoading = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue