Skip to content

Commit 2eab753

Browse files
committed
version 1.3.3; 修正输入与选择不一致问题(但现在特殊输入不会正常运行); 现在同步完成的空格输入不作为确认按键;
1 parent f2610d7 commit 2eab753

File tree

7 files changed

+144
-38
lines changed

7 files changed

+144
-38
lines changed

src/Intellisense/IIdeographCompletion.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
namespace ChinesePinyinIntelliSenseExtender.Intellisense;
44

55
/// <summary>
6-
/// 表意文字完成
6+
/// 表意文字完成项
77
/// </summary>
88
internal interface IIdeographCompletion
9+
{
10+
}
11+
12+
/// <summary>
13+
/// 表意文字可匹配完成项
14+
/// </summary>
15+
internal interface IIdeographMatchableCompletion : IIdeographCompletion
916
{
1017
#region Public 属性
1118

src/Intellisense/SyncCompletion/IdeographCompletionCommandHandler.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pv
8484
{
8585
if (completionSession.SelectedCompletionSet.SelectionStatus.IsSelected)
8686
{
87-
completionSession.Commit();
87+
if (isTypedWhiteSpace) //暂时取消空格输入,避免类似:输入 int 后键入空格,会插入模糊匹配的完成项
88+
{
89+
completionSession.Dismiss();
90+
}
91+
else
92+
{
93+
completionSession.Commit();
94+
}
8895
if (isTypedWhiteSpace || isTypedPunctuation)
8996
{
9097
_nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);

src/Intellisense/SyncCompletion/IdeographCompletionSource.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public void AugmentCompletionSession(ICompletionSession session, IList<Completio
5151
{
5252
foreach (var completion in allCompletions)
5353
{
54-
itemBuffer[bufferIndex++] = completion;
54+
//暂时必须克隆完成项,使用之前的完成项会导致显示与实际插入不同的问题,暂未寻找解决方案
55+
//克隆目前会导致特殊输入失效,如 <新建事件> ,暂未寻找解决方案
56+
itemBuffer[bufferIndex++] = CloneCompletion(completion);
5557
}
5658

5759
var processedCompletionSet = CreateNewCompletionSet(completionSet, new ArrayBaseEnumerator<Completion>(itemBuffer, 0, bufferIndex));
@@ -86,18 +88,31 @@ private static CompletionSet CreateNewCompletionSet(CompletionSet completionSet,
8688
}
8789
}
8890

91+
private Completion CloneCompletion(Completion originCompletion)
92+
{
93+
return originCompletion switch
94+
{
95+
Completion4 completion4 => completion4.Suffix?.Length > 0
96+
? new IdeographCompletion4(displayText: completion4.DisplayText, suffix: completion4.Suffix, origin: completion4)
97+
: new IdeographCompletion4(displayText: completion4.DisplayText, origin: completion4),
98+
Completion3 completion3 => new IdeographCompletion3(displayText: completion3.DisplayText, origin: completion3),
99+
Completion2 completion2 => new IdeographCompletion2(displayText: completion2.DisplayText, origin: completion2),
100+
_ => new IdeographCompletion(displayText: originCompletion.DisplayText, origin: originCompletion),
101+
};
102+
}
103+
89104
private Completion CreateCompletion(Completion originCompletion, string originInsertText, string spelling)
90105
{
91106
var displayText = FormatString(Options.SyncCompletionDisplayTextFormat, spelling, originInsertText);
92107

93108
return originCompletion switch
94109
{
95110
Completion4 completion4 => completion4.Suffix?.Length > 0
96-
? new IdeographCompletion4(displayText: displayText, suffix: completion4.Suffix, matchText: spelling, origin: completion4)
97-
: new IdeographCompletion4(displayText: displayText, matchText: spelling, origin: completion4),
98-
Completion3 completion3 => new IdeographCompletion3(displayText: displayText, matchText: spelling, origin: completion3),
99-
Completion2 completion2 => new IdeographCompletion2(displayText: displayText, matchText: spelling, origin: completion2),
100-
_ => new IdeographCompletion(displayText: displayText, matchText: spelling, origin: originCompletion),
111+
? new IdeographMatchableCompletion4(displayText: displayText, suffix: completion4.Suffix, matchText: spelling, origin: completion4)
112+
: new IdeographMatchableCompletion4(displayText: displayText, matchText: spelling, origin: completion4),
113+
Completion3 completion3 => new IdeographMatchableCompletion3(displayText: displayText, matchText: spelling, origin: completion3),
114+
Completion2 completion2 => new IdeographMatchableCompletion2(displayText: displayText, matchText: spelling, origin: completion2),
115+
_ => new IdeographMatchableCompletion(displayText: displayText, matchText: spelling, origin: originCompletion),
101116
};
102117
}
103118

src/Intellisense/SyncCompletion/IdeographCompletions.cs

Lines changed: 99 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace ChinesePinyinIntelliSenseExtender.Intellisense.SyncCompletion;
1010

11-
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
11+
[DebuggerDisplay("{_origin.DisplayText,nq}")]
1212
internal class IdeographCompletion : Completion, IIdeographCompletion
1313
{
1414
#region Private 字段
@@ -27,25 +27,22 @@ internal class IdeographCompletion : Completion, IIdeographCompletion
2727

2828
public override string InsertionText { get => _origin.InsertionText; set => _origin.InsertionText = value; }
2929

30-
public string MatchText { get; }
31-
3230
public override PropertyCollection Properties => _origin.Properties;
3331

3432
#endregion Public 属性
3533

3634
#region Public 构造函数
3735

38-
public IdeographCompletion(string displayText, string matchText, Completion origin)
36+
public IdeographCompletion(string displayText, Completion origin)
3937
{
4038
DisplayText = displayText;
41-
MatchText = matchText;
4239
_origin = origin;
4340
}
4441

4542
#endregion Public 构造函数
4643
}
4744

48-
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
45+
[DebuggerDisplay("{_origin.DisplayText,nq}")]
4946
internal class IdeographCompletion2 : Completion2, IIdeographCompletion
5047
{
5148
#region Private 字段
@@ -66,25 +63,22 @@ internal class IdeographCompletion2 : Completion2, IIdeographCompletion
6663

6764
public override string InsertionText { get => _origin.InsertionText; set => _origin.InsertionText = value; }
6865

69-
public string MatchText { get; }
70-
7166
public override PropertyCollection Properties => _origin.Properties;
7267

7368
#endregion Public 属性
7469

7570
#region Public 构造函数
7671

77-
public IdeographCompletion2(string displayText, string matchText, Completion2 origin)
72+
public IdeographCompletion2(string displayText, Completion2 origin)
7873
{
7974
DisplayText = displayText;
80-
MatchText = matchText;
8175
_origin = origin;
8276
}
8377

8478
#endregion Public 构造函数
8579
}
8680

87-
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
81+
[DebuggerDisplay("{_origin.DisplayText,nq}")]
8882
internal class IdeographCompletion3 : Completion3, IIdeographCompletion
8983
{
9084
#region Private 字段
@@ -107,25 +101,22 @@ internal class IdeographCompletion3 : Completion3, IIdeographCompletion
107101

108102
public override string InsertionText { get => _origin.InsertionText; set => _origin.InsertionText = value; }
109103

110-
public string MatchText { get; }
111-
112104
public override PropertyCollection Properties => _origin.Properties;
113105

114106
#endregion Public 属性
115107

116108
#region Public 构造函数
117109

118-
public IdeographCompletion3(string displayText, string matchText, Completion3 origin)
110+
public IdeographCompletion3(string displayText, Completion3 origin)
119111
{
120112
DisplayText = displayText;
121-
MatchText = matchText;
122113
_origin = origin;
123114
}
124115

125116
#endregion Public 构造函数
126117
}
127118

128-
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
119+
[DebuggerDisplay("{_origin.DisplayText,nq}")]
129120
internal class IdeographCompletion4 : Completion4, IIdeographCompletion
130121
{
131122
#region Private 字段
@@ -148,28 +139,114 @@ internal class IdeographCompletion4 : Completion4, IIdeographCompletion
148139

149140
public override string InsertionText { get => _origin.InsertionText; set => _origin.InsertionText = value; }
150141

151-
public string MatchText { get; }
152-
153142
public override PropertyCollection Properties => _origin.Properties;
154143

155144
#endregion Public 属性
156145

157146
#region Public 构造函数
158147

159-
public IdeographCompletion4(string displayText, string suffix, string matchText, Completion4 origin)
148+
public IdeographCompletion4(string displayText, string suffix, Completion4 origin)
160149
: base(displayText: null, insertionText: null, description: null, iconMoniker: default, suffix: suffix)
161150
{
162151
DisplayText = displayText;
163-
MatchText = matchText;
164152
_origin = origin;
165153
}
166154

167-
public IdeographCompletion4(string displayText, string matchText, Completion4 origin)
155+
public IdeographCompletion4(string displayText, Completion4 origin)
168156
{
169157
DisplayText = displayText;
170-
MatchText = matchText;
171158
_origin = origin;
172159
}
173160

174161
#endregion Public 构造函数
175162
}
163+
164+
#region Matchable
165+
166+
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
167+
internal class IdeographMatchableCompletion : IdeographCompletion, IIdeographMatchableCompletion
168+
{
169+
#region Public 属性
170+
171+
public string MatchText { get; }
172+
173+
#endregion Public 属性
174+
175+
#region Public 构造函数
176+
177+
public IdeographMatchableCompletion(string displayText, string matchText, Completion origin)
178+
: base(displayText, origin)
179+
{
180+
MatchText = matchText;
181+
}
182+
183+
#endregion Public 构造函数
184+
}
185+
186+
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
187+
internal class IdeographMatchableCompletion2 : IdeographCompletion2, IIdeographMatchableCompletion
188+
{
189+
#region Public 属性
190+
191+
public string MatchText { get; }
192+
193+
#endregion Public 属性
194+
195+
#region Public 构造函数
196+
197+
public IdeographMatchableCompletion2(string displayText, string matchText, Completion2 origin)
198+
: base(displayText, origin)
199+
{
200+
MatchText = matchText;
201+
}
202+
203+
#endregion Public 构造函数
204+
}
205+
206+
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
207+
internal class IdeographMatchableCompletion3 : IdeographCompletion3, IIdeographMatchableCompletion
208+
{
209+
#region Public 属性
210+
211+
public string MatchText { get; }
212+
213+
#endregion Public 属性
214+
215+
#region Public 构造函数
216+
217+
public IdeographMatchableCompletion3(string displayText, string matchText, Completion3 origin)
218+
: base(displayText, origin)
219+
{
220+
MatchText = matchText;
221+
}
222+
223+
#endregion Public 构造函数
224+
}
225+
226+
[DebuggerDisplay("{_origin.DisplayText,nq} [{MatchText,nq}]")]
227+
internal class IdeographMatchableCompletion4 : IdeographCompletion4, IIdeographMatchableCompletion
228+
{
229+
#region Public 属性
230+
231+
public string MatchText { get; }
232+
233+
#endregion Public 属性
234+
235+
#region Public 构造函数
236+
237+
public IdeographMatchableCompletion4(string displayText, string suffix, string matchText, Completion4 origin)
238+
: base(displayText, suffix, origin)
239+
{
240+
MatchText = matchText;
241+
}
242+
243+
public IdeographMatchableCompletion4(string displayText, string matchText, Completion4 origin)
244+
: base(displayText, origin)
245+
{
246+
MatchText = matchText;
247+
}
248+
249+
#endregion Public 构造函数
250+
}
251+
252+
#endregion Matchable

src/Intellisense/SyncCompletion/InnerIdeographCompletionSet.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public InnerIdeographCompletionSet(CompletionSet completionSet, FilteredObservab
6767

6868
private bool DoesCompletionMatchApplicabilityText(Completion completion, string inputText)
6969
{
70-
if (completion is IIdeographCompletion ideographCompletion
71-
&& ideographCompletion.MatchText is not null)
70+
if (completion is IIdeographMatchableCompletion ideographMatchableCompletion
71+
&& ideographMatchableCompletion.MatchText is not null)
7272
{
73-
return InputTextMatchHelper.CalculateMatchScore(inputText, ideographCompletion.MatchText, out _) > 0;
73+
return InputTextMatchHelper.CalculateMatchScore(inputText, ideographMatchableCompletion.MatchText, out _) > 0;
7474
}
7575
else
7676
{

src/Util/CompletionSetSelectBestMatchHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ internal static class CompletionSetSelectBestMatchHelper
2929

3030
foreach (var completion in completionList)
3131
{
32-
var currentMatchText = completion is IIdeographCompletion ideographCompletion
33-
? ideographCompletion.MatchText
32+
var currentMatchText = completion is IIdeographMatchableCompletion ideographMatchableCompletion
33+
? ideographMatchableCompletion.MatchText
3434
: completion.DisplayText;
3535

3636
if (string.IsNullOrEmpty(currentMatchText)
@@ -80,11 +80,11 @@ internal static class CompletionSetSelectBestMatchHelper
8080
public static CompletionSelectionStatus SelectSelectionStatus(CompletionSelectionStatus compareSelectionStatus, CompletionSelectionStatus baseSelectionStatus, string inputText)
8181
{
8282
if (baseSelectionStatus?.Completion is not { } baseSelectedCompletion
83-
|| compareSelectionStatus.Completion is not IIdeographCompletion compareSelectedCompletion) //基类未选择
83+
|| compareSelectionStatus.Completion is not IIdeographMatchableCompletion compareSelectedCompletion) //基类未选择
8484
{
8585
return compareSelectionStatus;
8686
}
87-
if (baseSelectedCompletion is IIdeographCompletion) //基类选择了 IIdeographCompletion
87+
if (baseSelectedCompletion is IIdeographMatchableCompletion) //基类选择了 IIdeographMatchableCompletion
8888
{
8989
return compareSelectionStatus;
9090
}

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.3.2" Language="en-US" Publisher="Stratos" />
4+
<Identity Id="ChinesePinyinIntelliSenseExtender.4293B766-9575-4472-B6F0-98BD86737E0D" Version="1.3.3" Language="en-US" Publisher="Stratos" />
55
<DisplayName>IntelliSense汉语拼音拓展</DisplayName>
66
<Description xml:space="preserve">汉语拼音的IntelliSense拓展。(支持基于 IAsyncCompletionSource 的完成,如: C#、JS等;支持自定义字符映射;)</Description>
77
<MoreInfo>https://github.com/stratosblue/chinesepinyinintellisenseextender</MoreInfo>

0 commit comments

Comments
 (0)