Compare commits

...

12 Commits

Author SHA1 Message Date
Yu Leng
c4120e9468 Remove Chinese Pinyin matching functionality
Removed the `ToolGood.Words.Pinyin` package and all related
logic from the `Common.Search` project. This includes the
removal of the `ChinesePinYinSupport` property in the
`MatchOption` class and the associated `IsSimplifiedChinese`
method. Simplified the `StringMatcher` class by eliminating
Pinyin-based transformations and focusing solely on direct
fuzzy matching of input strings. These changes reduce
dependencies and streamline the codebase.
2025-12-08 08:52:44 +08:00
Yu Leng
9ec0372f52 Refactor SettingsViewModel and enhance Chinese detection
Removed the `AutoGoBackIntervalIndex` property from the
`SettingsViewModel` class as part of a refactor or feature
removal.

Enhanced the `IsSimplifiedChinese` method in the
`FuzzyStringMatcher` class to improve detection of Simplified
Chinese by adding checks for culture names starting with
"zh-CN", "zh-Hans", or "zh-Hans-*".
2025-12-08 08:37:24 +08:00
Yu Leng
9db2ebee68 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.
2025-12-08 08:13:23 +08:00
舰队的偶像-岛风酱!
ceb554a738 Merge branch 'main' into feat/pinyin-next 2025-12-07 10:14:26 +08:00
舰队的偶像-岛风酱!
e24a89d322 feat(StringMatcher): add Chinese PinYin support option
- Add ChinesePinYinSupport property to MatchOption class
- Implement Chinese PinYin support in StringMatcher class
- Implement Chinese PinYin support in FuzzyStringMatcher class
- Use the new option to conditionally enable Chinese PinYin matching

Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
2025-10-23 18:17:17 +08:00
舰队的偶像-岛风酱!
cd188aa281 Update NOTICE.md 2025-10-23 18:08:30 +08:00
舰队的偶像-岛风酱!
8d8e83d09e ci: update spell check whitelist
- Add 'toolgood' to the list of expected words
- Maintain existing entries and order

Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
2025-10-23 18:08:30 +08:00
舰队的偶像-岛风酱!
18d040cc91 trans(cmdpal): update Chinese PinYin support settings text
- Rename "Enable Chinese PinYin Support" to "PinYin Support for Chinese"
- Update description from "Allows searching for Chinese characters using PinYin" to "Search Chinese contents with PinYin"

thanks @sovetskyfish

Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
2025-10-23 18:08:30 +08:00
舰队的偶像-岛风酱!
92fb827b3a feat(cmdpal): add option to enable Chinese PinYin support
- Add EnableChinesePinYinSupport setting to SettingsModel
- Implement EnableChinesePinYinSupport property in SettingsViewModel
- Create UI toggle for EnableChinesePinYinSupport in GeneralPage.xaml
- Add localization strings for new Chinese PinYin support setting

Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
2025-10-23 18:08:29 +08:00
舰队的偶像-岛风酱!
390dfdc8d1 build(deps): update ToolGood.Words.Pinyin to 3.1.0.3
- Upgraded ToolGood.Words.Pinyin package from version 3.1.0.2 to 3.1.0.3

Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
2025-10-23 18:08:29 +08:00
舰队的偶像-岛风酱!
f345c2451c docs: add notice for ToolGood.Words.Pinyin dependency
- Added notice for the use of ToolGood.Words.Pinyin NuGet package
- Included MIT License information for ToolGood.Words.Pinyin
- Updated NOTICE.md to reflect the new dependency

Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
2025-10-23 18:08:29 +08:00
舰队的偶像-岛风酱!
b49e33cd90 feat(cmdpal): add pinyin support for Chinese input method
- Add ToolGood.Words.Pinyin package to support pinyin conversion
- Implement pinyin matching in StringMatcher class
- Implement pinyin matching in FuzzyStringMatcher class
- Update project dependencies and Directory.Packages.props

Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
2025-10-23 18:07:32 +08:00
5 changed files with 76 additions and 0 deletions

View File

@@ -1798,6 +1798,7 @@ tlbimp
tlc
tmain
TNP
toolgood
Toolhelp
toolwindow
TOPDOWNDIB

View File

@@ -118,6 +118,7 @@
<PackageVersion Include="System.Text.Encoding.CodePages" Version="9.0.10" />
<PackageVersion Include="System.Text.Json" Version="9.0.10" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="ToolGood.Words.Pinyin" Version="3.1.0.3" />
<PackageVersion Include="UnicodeInformation" Version="2.6.0" />
<PackageVersion Include="UnitsNet" Version="5.56.0" />
<PackageVersion Include="UTF.Unknown" Version="2.6.0" />

View File

@@ -75,6 +75,37 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
```
### ToolGood.Words.Pinyin
We use the ToolGood.Words.Pinyin NuGet package for converting Chinese characters to pinyin.
**Source**: [https://github.com/toolgood/ToolGood.Words.Pinyin](https://github.com/toolgood/ToolGood.Words.Pinyin)
```
MIT License
Copyright (c) 2020 ToolGood
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
## Utility: Command Palette Built-in Extensions
### Calculator
@@ -1532,6 +1563,7 @@ SOFTWARE.
- SkiaSharp.Views.WinUI
- StreamJsonRpc
- StyleCop.Analyzers
- ToolGood.Words.Pinyin
- UnicodeInformation
- UnitsNet
- UTF.Unknown

View File

@@ -2,6 +2,10 @@
// 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;
// Inspired by the fuzzy.rs from edit.exe
@@ -9,6 +13,21 @@ public static class FuzzyStringMatcher
{
private const int NOMATCH = 0;
/// <summary>
/// Gets a value indicating whether to support Chinese PinYin.
/// Automatically enabled when the system UI culture is Simplified Chinese.
/// </summary>
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)
{
var (s, _) = ScoreFuzzyWithPositions(needle, haystack, allowNonContiguousMatches);
@@ -16,6 +35,28 @@ public static class FuzzyStringMatcher
}
public static (int Score, List<int> Positions) ScoreFuzzyWithPositions(string needle, string haystack, bool allowNonContiguousMatches)
=> ScoreAllFuzzyWithPositions(needle, haystack, allowNonContiguousMatches).MaxBy(i => i.Score);
public static IEnumerable<(int Score, List<int> Positions)> ScoreAllFuzzyWithPositions(string needle, string haystack, bool allowNonContiguousMatches)
{
List<string> needles = [needle];
List<string> haystacks = [haystack];
if (ChinesePinYinSupport)
{
// Remove IME composition split characters.
var input = needle.Replace("'", string.Empty);
needles.Add(WordsHelper.GetPinyin(input));
if (WordsHelper.HasChinese(haystack))
{
haystacks.Add(WordsHelper.GetPinyin(haystack));
}
}
return needles.SelectMany(i => haystacks.Select(j => ScoreFuzzyWithPositionsInternal(i, j, allowNonContiguousMatches)));
}
private static (int Score, List<int> Positions) ScoreFuzzyWithPositionsInternal(string needle, string haystack, bool allowNonContiguousMatches)
{
if (string.IsNullOrEmpty(haystack) || string.IsNullOrEmpty(needle))
{

View File

@@ -42,6 +42,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Drawing.Common" />
<PackageReference Include="ToolGood.Words.Pinyin" />
<!-- This line forces the WebView2 version used by Windows App SDK to be the one we expect from Directory.Packages.props . -->
</ItemGroup>