Skip to content

Commit b3c1f1a

Browse files
committed
opt: 优化同步完成的匹配规则
1 parent e03f207 commit b3c1f1a

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

src/Intellisense/SyncCompletion/IdeographCompletionCommandHandler.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,18 @@ public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pv
8383
{
8484
if (completionSession.SelectedCompletionSet.SelectionStatus.IsSelected)
8585
{
86-
if (isTypedWhiteSpace) //暂时取消空格输入,避免类似:输入 int 后键入空格,会插入模糊匹配的完成项
87-
{
88-
completionSession.Dismiss();
89-
}
90-
else
91-
{
92-
completionSession.Commit();
93-
}
86+
// 暂时调整了匹配逻辑,至少int可以正常输入了,开启空格输入
87+
//if (isTypedWhiteSpace) //暂时取消空格输入,避免类似:输入 int 后键入空格,会插入模糊匹配的完成项
88+
//{
89+
// completionSession.Dismiss();
90+
//}
91+
//else
92+
//{
93+
// completionSession.Commit();
94+
//}
95+
96+
completionSession.Commit();
97+
9498
if (isTypedWhiteSpace || isTypedPunctuation)
9599
{
96100
_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);

src/Util/InputTextMatchHelper.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static int CalculateMatchScore(string inputText, string matchText, out in
2626

2727
const int InvalidSocre = -1; //无效分数
2828
const int InitSocreRewards = 1; //初始分数奖励
29-
const int UpperMatchSocre = 5; //大写匹配分数
29+
const int SpecialMatchSocre = 5; //特殊匹配分数 - AaaBbb 中的 B; aaa_bbb 中 _ 后的 b
3030

3131
var currentCompletionScore = InvalidSocre;
3232
charsMatchedCount = 0;
@@ -55,19 +55,21 @@ public static int CalculateMatchScore(string inputText, string matchText, out in
5555
}
5656
}
5757
return i == matchText.Length - 1
58-
? i * 1000 * UpperMatchSocre
59-
: i * 100 * UpperMatchSocre;
58+
? i * 1000 * SpecialMatchSocre
59+
: i * 100 * SpecialMatchSocre;
6060
}
6161

6262
//下方逻辑是从 CompletionSet 中 copy 后改的
6363

6464
var inputIndex = 0;
6565
var matchIndex = 0;
6666
var scoreRewards = InitSocreRewards; //分数奖励
67+
var preOriginMatchChar = char.MinValue; //上一个原始匹配字符
6768

6869
for (; inputIndex < inputLength; inputIndex++)
6970
{
7071
var inputChar = char.ToLowerInvariant(inputText[inputIndex]);
72+
preOriginMatchChar = char.MinValue;
7173

7274
for (; matchIndex < matchLength;)
7375
{
@@ -87,22 +89,27 @@ public static int CalculateMatchScore(string inputText, string matchText, out in
8789
continue;
8890
}
8991

90-
if (char.IsUpper(originMatchChar)) //大写字母匹配
92+
if (char.IsUpper(originMatchChar)) //当前为大写字母匹配
9193
{
92-
currentCompletionScore += UpperMatchSocre + scoreRewards;
94+
if (char.IsLower(preOriginMatchChar)
95+
|| char.IsPunctuation(preOriginMatchChar)) //上一个为小写或符号
96+
{
97+
currentCompletionScore += SpecialMatchSocre;
98+
}
9399
}
94-
else
100+
else if (char.IsLower(originMatchChar)) //当前为小写字母匹配
95101
{
96-
currentCompletionScore += scoreRewards; //普通匹配
102+
if (char.IsPunctuation(preOriginMatchChar)) //上一个为符号
103+
{
104+
currentCompletionScore += SpecialMatchSocre;
105+
}
97106
}
98107

99-
if (matchIndex == 0) //首字母匹配
100-
{
101-
currentCompletionScore += UpperMatchSocre;
102-
}
108+
currentCompletionScore += scoreRewards; //普通匹配
103109

104110
scoreRewards++; //增加匹配分
105111
charsMatchedCount++;
112+
preOriginMatchChar = originMatchChar;
106113
break;
107114
}
108115
}
@@ -118,6 +125,11 @@ public static int CalculateMatchScore(string inputText, string matchText, out in
118125
if (charsMatchedCount == matchLength) //完整匹配目标项
119126
{
120127
currentCompletionScore *= 12 * inputLength;
128+
//大小写完全匹配翻倍
129+
if (string.Equals(inputText, matchText, StringComparison.Ordinal))
130+
{
131+
currentCompletionScore *= 2;
132+
}
121133
}
122134
else
123135
{

src/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="ChinesePinyinIntelliSenseExtender.4293B766-9575-4472-B6F0-98BD86737E0D" Version="1.4.3" Language="en-US" Publisher="Stratos" />
4+
<Identity Id="ChinesePinyinIntelliSenseExtender.4293B766-9575-4472-B6F0-98BD86737E0D" Version="1.4.4" Language="en-US" Publisher="Stratos" />
55
<DisplayName>IntelliSense汉语拼音拓展</DisplayName>
66
<Description xml:space="preserve">表意文字补全拓展(内置汉语拼音、五笔,支持自定义字符映射;)</Description>
77
<MoreInfo>https://github.com/stratosblue/chinesepinyinintellisenseextender</MoreInfo>

0 commit comments

Comments
 (0)