From 9db2ebee6830d8f9cc84c813bdf514f13bce99bc Mon Sep 17 00:00:00 2001 From: Yu Leng Date: Fri, 5 Dec 2025 11:42:40 +0800 Subject: [PATCH] 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. --- .../Common.Search/FuzzSearch/MatchOption.cs | 15 +++++++++++++-- .../SettingsModel.cs | 12 ------------ .../SettingsViewModel.cs | 9 --------- .../Microsoft.CmdPal.UI/Settings/GeneralPage.xaml | 3 --- .../Strings/en-us/Resources.resw | 6 ------ .../FuzzyStringMatcher.cs | 15 +++++++++++++-- 6 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/common/Common.Search/FuzzSearch/MatchOption.cs b/src/common/Common.Search/FuzzSearch/MatchOption.cs index 6b4c3f981f..18d977e50a 100644 --- a/src/common/Common.Search/FuzzSearch/MatchOption.cs +++ b/src/common/Common.Search/FuzzSearch/MatchOption.cs @@ -2,6 +2,8 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; + namespace Common.Search.FuzzSearch; public class MatchOption @@ -9,7 +11,16 @@ public class MatchOption public bool IgnoreCase { get; set; } = true; /// - /// 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. /// - 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); + } } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs index 9f67077c35..dae50b3f3e 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs @@ -46,18 +46,6 @@ public partial class SettingsModel : ObservableObject public bool AllowExternalReload { get; set; } - public bool EnableChinesePinYinSupport - { - get => field; - set - { - if (SetProperty(ref field, value)) - { - FuzzyStringMatcher.ChinesePinYinSupport = value; - } - } - } - public Dictionary ProviderSettings { get; set; } = []; public Dictionary Aliases { get; set; } = []; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsViewModel.cs index f755855df1..b871ecda44 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsViewModel.cs @@ -141,15 +141,6 @@ public partial class SettingsViewModel : INotifyPropertyChanged } } - public bool EnableChinesePinYinSupport - { - get => _settings.EnableChinesePinYinSupport; - set - { - _settings.EnableChinesePinYinSupport = value; - Save(); - } - } public int AutoGoBackIntervalIndex { diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml index 040d6eb2ea..eb0264a683 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml @@ -51,9 +51,6 @@ - - - diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw b/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw index 930fe6e55a..6ed0a3bfaa 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw @@ -344,12 +344,6 @@ Right-click to remove the key combination, thereby deactivating the shortcut. Preventing disruption of the program running in fullscreen by unintentional activation of shortcut - - PinYin Support for Chinese - - - Search Chinese contents with PinYin - Highlight search on activate diff --git a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FuzzyStringMatcher.cs b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FuzzyStringMatcher.cs index 74696ab31b..83d42953c2 100644 --- a/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FuzzyStringMatcher.cs +++ b/src/modules/cmdpal/extensionsdk/Microsoft.CommandPalette.Extensions.Toolkit/FuzzyStringMatcher.cs @@ -2,6 +2,8 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Globalization; + using ToolGood.Words.Pinyin; namespace Microsoft.CommandPalette.Extensions.Toolkit; @@ -12,9 +14,18 @@ public static class FuzzyStringMatcher private const int NOMATCH = 0; /// - /// 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. /// - 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) {