Skip to content

Commit

Permalink
重构 拼音搜索底层算法
Browse files Browse the repository at this point in the history
优化 搜索被匹配关键词显示
  • Loading branch information
MakesYT committed Oct 26, 2024
1 parent 148276f commit 5d970c2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions Core/ViewModel/SearchWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ partial void OnSearchChanged(string? value)
}
Items.Add(searchViewItem); // 添加元素
searchViewItem.Notify();
count++; // 计数器加一
}
}
Expand Down
10 changes: 5 additions & 5 deletions KitopiaAvalonia/Converter/SearchWindow/ItemNameMatchCtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public class ItemNameMatchCtr : IValueConverter
return new InlineCollection();
}

InlineCollection list = new();
if (str.PinyinItem == null || str.PinyinItem.CharMatchResults == null || str.PinyinItem.SplitWords == null ||
str.PinyinItem.CharMatchResults.Length - str.PinyinItem.ZhongWenCount != str.PinyinItem.SplitWords.Length ||
str.PinyinItem.CharMatchResults.Length == 0)
InlineCollection list = new(); if (str.PinyinItem == null || str.PinyinItem.CharMatchResults == null || str.PinyinItem.SplitWords == null ||
str.PinyinItem.CharMatchResults.Length == 0||
str.PinyinItem.CharMatchResults.Length /2 != str.PinyinItem.SplitWords.Length
)
{
list.Add(new Run(str.ItemDisplayName));
return list;
Expand All @@ -33,7 +33,7 @@ public class ItemNameMatchCtr : IValueConverter
for (int i = 0; i < str.PinyinItem.SplitWords.Length; i++)
{
var inline = new Run(str.PinyinItem.SplitWords[i]);
if (str.PinyinItem.CharMatchResults[i + str.PinyinItem.ZhongWenCount])
if (str.PinyinItem.CharMatchResults[i + str.PinyinItem.SplitWords.Length])
{
inline.Foreground = Brushes.OrangeRed;
}
Expand Down
2 changes: 1 addition & 1 deletion KitopiaAvalonia/Windows/SearchWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
HorizontalAlignment="Stretch">
<TextBlock VerticalAlignment="Center" Margin="0" Focusable="False"
FontFamily="HarmonyOS Sans"
Inlines="{Binding Path=.,
Inlines="{Binding Path=PinyinItem,
Converter={StaticResource ItemNameMatchCtr},
ConverterParameter={ReflectionBinding #Item}}"
Background="{x:Null}"
Expand Down
3 changes: 3 additions & 0 deletions KitopiaAvalonia/Windows/SearchWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public SearchWindow()
InitializeComponent();
WeakReferenceMessenger.Default.Register<string, string>(this, "SearchWindowClose",
(_, _) => { Dispatcher.UIThread.InvokeAsync(() => { IsVisible = false; }); });
#if DEBUG
this.Topmost = false;
#endif
}

public override void Show()
Expand Down
2 changes: 1 addition & 1 deletion PluginCore
Submodule PluginCore updated 1 files
+8 −5 SearchViewItem.cs

0 comments on commit 5d970c2

Please sign in to comment.