Skip to content

fix: 搜索防抖、防止旧结果覆盖新搜索、修复 Windows 假失焦#1252

Open
Moeblack wants to merge 1 commit into
EcoPasteHub:masterfrom
Moeblack:fix/search-debounce-blur
Open

fix: 搜索防抖、防止旧结果覆盖新搜索、修复 Windows 假失焦#1252
Moeblack wants to merge 1 commit into
EcoPasteHub:masterfrom
Moeblack:fix/search-debounce-blur

Conversation

@Moeblack
Copy link
Copy Markdown

@Moeblack Moeblack commented Feb 6, 2026

概述

修复搜索历史记录时的三个问题:频繁查库卡顿、旧搜索结果覆盖新搜索、Windows 上假失焦导致窗口消失/搜索框清空。

问题 1:搜索无防抖

每个按键都立即触发一次数据库查询,快速输入时造成多次无意义的全表扫描。

修复:SearchInput 添加 200ms 防抖。

问题 2:旧搜索结果覆盖新搜索

用户快速输入时,先发出的查询可能晚于后发的查询返回,导致列表显示旧结果(视觉上"搜索回退")。

修复

  • 添加 fetchId 机制,每次查询递增 ID,返回时比对是否仍是最新请求
  • 添加 queryKey 比对,确保结果对应当前搜索条件
  • 添加 pendingReload,查询中途触发新搜索时自动接力

问题 3:Windows 假失焦

Windows 上 onFocusChanged 偶尔会发出错误的失焦事件,触发 hideWindow() 隐藏窗口和 autoClear 清空搜索框。

修复useTauriFocus 在收到失焦事件后,用 appWindow.isFocused() 二次确认,减少误触发。

相关 issues:#524 #882 #966

- SearchInput 添加 200ms 防抖,减少频繁查库
- useHistoryList 添加 fetchId 机制,丢弃过期请求结果,防止旧结果覆盖新搜索
- useHistoryList 添加 pendingReload,查询中途触发新搜索时自动接力
- useTauriFocus 添加 isFocused() 二次确认,缓解 Windows 上假失焦导致的 hideWindow/autoClear

相关 issues:EcoPasteHub#524 EcoPasteHub#882 EcoPasteHub#966
@Moeblack Moeblack force-pushed the fix/search-debounce-blur branch from 445c425 to f5906ae Compare February 6, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant