Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Ink Canvas/Windows/SettingsViews/Pages/SearchPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<ui:Page x:Class="Ink_Canvas.Windows.SettingsViews.Pages.SearchPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:props="clr-namespace:Ink_Canvas.Properties"
mc:Ignorable="d"
Title="Search">

<Grid Margin="59,0,59,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!-- 搜索框居中偏上 -->
<ui:AutoSuggestBox
x:Name="SearchBox"
Grid.Row="0"
MaxWidth="600"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Margin="0,80,0,0"
FontSize="14"
CornerRadius="8"
PlaceholderText="{x:Static props:NavStrings.Nav_SearchSettings}"
QuerySubmitted="SearchBox_QuerySubmitted"
TextChanged="SearchBox_TextChanged"
GotFocus="SearchBox_GotFocus"
KeyDown="SearchBox_KeyDown">
<ui:AutoSuggestBox.QueryIcon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Search}" FontSize="14"/>
</ui:AutoSuggestBox.QueryIcon>
</ui:AutoSuggestBox>

<!-- 搜索提示 -->
<TextBlock
x:Name="HintText"
Grid.Row="1"
Text="{x:Static props:NavStrings.Nav_SearchSettings}"
FontSize="13"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="0,24,0,0"/>
</Grid>
</ui:Page>
90 changes: 90 additions & 0 deletions Ink Canvas/Windows/SettingsViews/Pages/SearchPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using iNKORE.UI.WPF.Modern.Controls;

namespace Ink_Canvas.Windows.SettingsViews.Pages
{
public partial class SearchPage
{
/// <summary>
/// 选中搜索结果时触发,参数为 PageTag;"__back__" 表示返回
/// </summary>
public static event EventHandler<string> ResultSelected;

// 由 SettingsWindow 设置的静态搜索数据
internal static List<(string Text, string PageTag)> SearchData { get; set; }

public SearchPage()
{
InitializeComponent();
Loaded += (s, e) =>
{
Dispatcher.BeginInvoke(new Action(() => SearchBox.Focus()),
System.Windows.Threading.DispatcherPriority.Input);
};
}

private void SearchBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
if (SearchData == null) return;

string raw = (args.ChosenSuggestion as string) ?? args.QueryText;
if (string.IsNullOrWhiteSpace(raw)) return;

string query = raw.Trim();
var match = SearchData.Where(e => e.Text.Equals(query, StringComparison.OrdinalIgnoreCase))
.Concat(SearchData.Where(e => e.Text.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0))
.FirstOrDefault();

if (match.Text != null)
{
ResultSelected?.Invoke(this, match.PageTag);
}
}

private void SearchBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
if (args.Reason != AutoSuggestionBoxTextChangeReason.UserInput) return;
if (SearchData == null) return;

string query = sender.Text?.Trim() ?? string.Empty;
if (string.IsNullOrEmpty(query))
{
sender.ItemsSource = null;

@augmentcode augmentcode Bot Jun 27, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the query becomes empty, ItemsSource is cleared but IsSuggestionListOpen isn’t explicitly closed, so the suggestion popup can remain open from a previous non-empty query (empty dropdown UI glitch).

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

HintText.Visibility = Visibility.Visible;
return;
}

HintText.Visibility = Visibility.Collapsed;

var suggestions = SearchData
.Where(e => e.Text.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0)
.Select(e => e.Text)
.Distinct()
.Take(50)
.ToList();

sender.ItemsSource = suggestions;
sender.IsSuggestionListOpen = suggestions.Count > 0;
}

private void SearchBox_GotFocus(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(SearchBox.Text))
{
SearchBox.IsSuggestionListOpen = true;
}
}

private void SearchBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
ResultSelected?.Invoke(this, "__back__");
}
}
}
}
3 changes: 2 additions & 1 deletion Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ Title="{x:Static props:NavStrings.Nav_SettingsWindow_Title}"
x:FieldModifier="public"
PlaceholderText="{x:Static props:NavStrings.Nav_SearchSettings}"
QuerySubmitted="OnControlsSearchBoxQuerySubmitted"
TextChanged="OnControlsSearchBoxTextChanged">
TextChanged="OnControlsSearchBoxTextChanged"
GotFocus="OnControlsSearchBoxGotFocus">
<ui:AutoSuggestBox.QueryIcon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Search}" FontSize="12"/>
</ui:AutoSuggestBox.QueryIcon>
Expand Down
33 changes: 31 additions & 2 deletions Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public partial class SettingsWindow : Window
{ "AboutPage", typeof(AboutPage) },
{ "Settings", typeof(SettingsPage) },
{ "PluginPage", typeof(PluginPage) },
{ "PluginSettingsPage", typeof(PluginSettingsPage) }
{ "PluginSettingsPage", typeof(PluginSettingsPage) },
{ "SearchPage", typeof(SearchPage) }
};
private Dictionary<string, Type> _pageTypes;
private readonly Dictionary<string, object> _pages = new Dictionary<string, object>();
Expand Down Expand Up @@ -112,7 +113,8 @@ public SettingsWindow()
{ "AboutPage", typeof(AboutPage) },
{ "Settings", typeof(SettingsPage) },
{ "PluginPage", typeof(PluginPage) },
{ "PluginSettingsPage", typeof(PluginSettingsPage) }
{ "PluginSettingsPage", typeof(PluginSettingsPage) },
{ "SearchPage", typeof(SearchPage) }
};

// 默认选中首页
Expand Down Expand Up @@ -150,10 +152,12 @@ public SettingsWindow()
};

AnnouncementService.UnreadCountChanged += UpdateAnnouncementUnreadBadge;
SearchPage.ResultSelected += OnSearchPageResultSelected;

this.Closed += (sender, e) =>
{
AnnouncementService.UnreadCountChanged -= UpdateAnnouncementUnreadBadge;
SearchPage.ResultSelected -= OnSearchPageResultSelected;
UnregisterDpiChangedListener();
_pages.Clear();
_pageTypes.Clear();
Expand Down Expand Up @@ -737,6 +741,31 @@ private void OnControlsSearchBoxTextChanged(AutoSuggestBox sender, AutoSuggestBo
sender.ItemsSource = suggestions;
}

private void OnControlsSearchBoxGotFocus(object sender, RoutedEventArgs e)
{
// 构建搜索索引并传给 SearchPage
EnsureSearchIndexBuilt();
SearchPage.SearchData = _searchIndex
.Select(se => (se.Text, se.PageTag))
.ToList();
NavigateToPage("SearchPage");

@augmentcode augmentcode Bot Jun 27, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnControlsSearchBoxGotFocus always navigates to SearchPage; if focus returns to controlsSearchBox after rootFrame.GoBack() (e.g., ESC on SearchPage), this can immediately re-navigate and make “back” hard/impossible. Consider guarding against re-entry or ensuring focus moves away when returning.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

NavigationViewControl.Header = NavStrings.Nav_SearchSettings;
// 取消侧边栏选中状态
NavigationViewControl.SelectedItem = null;
}

private void OnSearchPageResultSelected(object sender, string pageTag)
{
if (pageTag == "__back__")
{
// 返回上一页
if (rootFrame.CanGoBack) rootFrame.GoBack();
return;
}

NavigateToSearchEntry(_searchIndex?.FirstOrDefault(e => e.PageTag == pageTag));
}

// 统一获取所有导航项(主菜单+子菜单+底部菜单)
private List<NavigationViewItem> GetAllNavigationItems()
{
Expand Down