Simplify Chinese PinYin support configuration

Removed manual toggle for Chinese PinYin support in settings and UI.
PinYin support is now automatically enabled based on the system's
UI culture (Simplified Chinese). Updated `MatchOption` and
`FuzzyStringMatcher` to include culture-based detection logic.
Removed related properties, UI elements, and resource strings.
This commit is contained in:
Yu Leng
2025-12-05 11:42:40 +08:00
parent ceb554a738
commit 9db2ebee68
6 changed files with 26 additions and 34 deletions

View File

@@ -2,6 +2,8 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Globalization;
namespace Common.Search.FuzzSearch; namespace Common.Search.FuzzSearch;
public class MatchOption public class MatchOption
@@ -9,7 +11,16 @@ public class MatchOption
public bool IgnoreCase { get; set; } = true; public bool IgnoreCase { get; set; } = true;
/// <summary> /// <summary>
/// Gets or sets a value indicating whether to support Chinese PinYin /// Gets or sets a value indicating whether to support Chinese PinYin.
/// Defaults to true when the system UI culture is Simplified Chinese.
/// </summary> /// </summary>
public bool ChinesePinYinSupport { get; set; } public bool ChinesePinYinSupport { get; set; } = IsSimplifiedChinese();
private static bool IsSimplifiedChinese()
{
var culture = CultureInfo.CurrentUICulture;
// Detect Simplified Chinese: zh-CN, zh-Hans, zh-Hans-*
return culture.Name.StartsWith("zh-CN", StringComparison.OrdinalIgnoreCase)
|| culture.Name.StartsWith("zh-Hans", StringComparison.OrdinalIgnoreCase);
}
} }

View File

@@ -46,18 +46,6 @@ public partial class SettingsModel : ObservableObject
public bool AllowExternalReload { get; set; } public bool AllowExternalReload { get; set; }
public bool EnableChinesePinYinSupport
{
get => field;
set
{
if (SetProperty(ref field, value))
{
FuzzyStringMatcher.ChinesePinYinSupport = value;
}
}
}
public Dictionary<string, ProviderSettings> ProviderSettings { get; set; } = []; public Dictionary<string, ProviderSettings> ProviderSettings { get; set; } = [];
public Dictionary<string, CommandAlias> Aliases { get; set; } = []; public Dictionary<string, CommandAlias> Aliases { get; set; } = [];

View File

@@ -141,15 +141,6 @@ public partial class SettingsViewModel : INotifyPropertyChanged
} }
} }
public bool EnableChinesePinYinSupport
{
get => _settings.EnableChinesePinYinSupport;
set
{
_settings.EnableChinesePinYinSupport = value;
Save();
}
}
public int AutoGoBackIntervalIndex public int AutoGoBackIntervalIndex
{ {

View File

@@ -51,9 +51,6 @@
</controls:SettingsCard> </controls:SettingsCard>
</controls:SettingsExpander.Items> </controls:SettingsExpander.Items>
</controls:SettingsExpander> </controls:SettingsExpander>
<controls:SettingsCard x:Uid="Settings_GeneralPage_EnableChinesePinYinSupport_SettingsCard" HeaderIcon="{ui:FontIcon Glyph=&#xE98A;}">
<ToggleSwitch IsOn="{x:Bind viewModel.EnableChinesePinYinSupport, Mode=TwoWay}" />
</controls:SettingsCard>
<controls:SettingsCard x:Uid="Settings_GeneralPage_AutoGoHome_SettingsCard" HeaderIcon="{ui:FontIcon Glyph=&#xE80F;}"> <controls:SettingsCard x:Uid="Settings_GeneralPage_AutoGoHome_SettingsCard" HeaderIcon="{ui:FontIcon Glyph=&#xE80F;}">
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind viewModel.AutoGoBackIntervalIndex, Mode=TwoWay}"> <ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind viewModel.AutoGoBackIntervalIndex, Mode=TwoWay}">
<ComboBoxItem x:Uid="Settings_GeneralPage_AutoGoHome_Item_Never" /> <ComboBoxItem x:Uid="Settings_GeneralPage_AutoGoHome_Item_Never" />

View File

@@ -344,12 +344,6 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
<data name="Settings_GeneralPage_IgnoreShortcutWhenFullscreen_SettingsCard.Description" xml:space="preserve"> <data name="Settings_GeneralPage_IgnoreShortcutWhenFullscreen_SettingsCard.Description" xml:space="preserve">
<value>Preventing disruption of the program running in fullscreen by unintentional activation of shortcut</value> <value>Preventing disruption of the program running in fullscreen by unintentional activation of shortcut</value>
</data> </data>
<data name="Settings_GeneralPage_EnableChinesePinYinSupport_SettingsCard.Header" xml:space="preserve">
<value>PinYin Support for Chinese</value>
</data>
<data name="Settings_GeneralPage_EnableChinesePinYinSupport_SettingsCard.Description" xml:space="preserve">
<value>Search Chinese contents with PinYin</value>
</data>
<data name="Settings_GeneralPage_HighlightSearch_SettingsCard.Header" xml:space="preserve"> <data name="Settings_GeneralPage_HighlightSearch_SettingsCard.Header" xml:space="preserve">
<value>Highlight search on activate</value> <value>Highlight search on activate</value>
</data> </data>

View File

@@ -2,6 +2,8 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Globalization;
using ToolGood.Words.Pinyin; using ToolGood.Words.Pinyin;
namespace Microsoft.CommandPalette.Extensions.Toolkit; namespace Microsoft.CommandPalette.Extensions.Toolkit;
@@ -12,9 +14,18 @@ public static class FuzzyStringMatcher
private const int NOMATCH = 0; private const int NOMATCH = 0;
/// <summary> /// <summary>
/// Gets or sets a value indicating whether to support Chinese PinYin /// Gets a value indicating whether to support Chinese PinYin.
/// Automatically enabled when the system UI culture is Simplified Chinese.
/// </summary> /// </summary>
public static bool ChinesePinYinSupport { get; set; } public static bool ChinesePinYinSupport { get; } = IsSimplifiedChinese();
private static bool IsSimplifiedChinese()
{
var culture = CultureInfo.CurrentUICulture;
// Detect Simplified Chinese: zh-CN, zh-Hans, zh-Hans-*
return culture.Name.StartsWith("zh-CN", StringComparison.OrdinalIgnoreCase)
|| culture.Name.StartsWith("zh-Hans", StringComparison.OrdinalIgnoreCase);
}
public static int ScoreFuzzy(string needle, string haystack, bool allowNonContiguousMatches = true) public static int ScoreFuzzy(string needle, string haystack, bool allowNonContiguousMatches = true)
{ {