1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
+ using System . Text ;
4
5
using System . Text . Json ;
5
6
using System . Text . Json . Serialization ;
6
7
using Avalonia . Collections ;
@@ -65,8 +66,8 @@ public string DefaultFontFamily
65
66
get => _defaultFontFamily ;
66
67
set
67
68
{
68
- var trimmed = value . Trim ( ) ;
69
- if ( SetProperty ( ref _defaultFontFamily , trimmed ) && ! _isLoading )
69
+ var name = FixFontFamilyName ( value ) ;
70
+ if ( SetProperty ( ref _defaultFontFamily , name ) && ! _isLoading )
70
71
App . SetFonts ( _defaultFontFamily , _monospaceFontFamily , _onlyUseMonoFontInEditor ) ;
71
72
}
72
73
}
@@ -76,8 +77,8 @@ public string MonospaceFontFamily
76
77
get => _monospaceFontFamily ;
77
78
set
78
79
{
79
- var trimmed = value . Trim ( ) ;
80
- if ( SetProperty ( ref _monospaceFontFamily , trimmed ) && ! _isLoading )
80
+ var name = FixFontFamilyName ( value ) ;
81
+ if ( SetProperty ( ref _monospaceFontFamily , name ) && ! _isLoading )
81
82
App . SetFonts ( _defaultFontFamily , _monospaceFontFamily , _onlyUseMonoFontInEditor ) ;
82
83
}
83
84
}
@@ -588,6 +589,35 @@ private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)
588
589
return changed ;
589
590
}
590
591
592
+ private string FixFontFamilyName ( string name )
593
+ {
594
+ var trimmed = name . Trim ( ) ;
595
+ if ( string . IsNullOrEmpty ( trimmed ) )
596
+ return string . Empty ;
597
+
598
+ var builder = new StringBuilder ( ) ;
599
+ var lastIsSpace = false ;
600
+ for ( int i = 0 ; i < trimmed . Length ; i ++ )
601
+ {
602
+ var c = trimmed [ i ] ;
603
+ if ( char . IsWhiteSpace ( c ) )
604
+ {
605
+ if ( lastIsSpace )
606
+ continue ;
607
+
608
+ lastIsSpace = true ;
609
+ }
610
+ else
611
+ {
612
+ lastIsSpace = false ;
613
+ }
614
+
615
+ builder . Append ( c ) ;
616
+ }
617
+
618
+ return builder . ToString ( ) ;
619
+ }
620
+
591
621
private static Preference _instance = null ;
592
622
private static bool _isLoading = false ;
593
623
0 commit comments