refactor: 删除自定义搜索,统一使用 CodeMirror 6 搜索

删除文件:
- SearchBar/SearchBar.tsx — 自定义搜索栏组件
- stores/searchStore.ts — 自定义搜索状态管理
- lib/searchEngine.ts — 自定义搜索匹配引擎
- types/search.ts — 搜索相关类型定义

清理代码:
- App.tsx:移除 SearchBar 导入和渲染
- useKeyboard.ts:移除 searchStore 引用和搜索快捷键
- Editor.tsx:移除 searchStore 引用和搜索逻辑
- types/index.ts:移除 search 类型导出
- global.css:删除旧搜索栏样式(~113 行)

CodeMirror 6 搜索面板移到顶部:
- .cm-panels { top: 0; bottom: auto; }
- .cm-panels-bottom { top: 0; bottom: auto; }

快捷键(CodeMirror 内置):
- Ctrl+F 搜索
- Ctrl+H 替换
- Enter/Shift+Enter 下一个/上一个
- Alt+C 大小写
- Alt+R 正则
This commit is contained in:
thzxx
2026-05-27 23:54:55 +08:00
parent e40a8bd88e
commit d57a2b2aac
9 changed files with 19 additions and 425 deletions
-64
View File
@@ -1,64 +0,0 @@
import { create } from 'zustand'
import type { SearchMatch, SearchOptions } from '../types/search'
interface SearchState {
isVisible: boolean
showReplace: boolean
searchText: string
replaceText: string
matches: SearchMatch[]
currentIndex: number
options: SearchOptions
setVisible: (visible: boolean) => void
setShowReplace: (show: boolean) => void
setSearchText: (text: string) => void
setReplaceText: (text: string) => void
setMatches: (matches: SearchMatch[]) => void
setCurrentIndex: (index: number) => void
toggleCaseSensitive: () => void
toggleRegex: () => void
findNext: () => void
findPrev: () => void
close: () => void
}
export const useSearchStore = create<SearchState>((set, get) => ({
isVisible: false,
showReplace: false,
searchText: '',
replaceText: '',
matches: [],
currentIndex: -1,
options: { caseSensitive: false, useRegex: false },
setVisible: (visible) => set({ isVisible: visible }),
setShowReplace: (show) => set({ showReplace: show }),
setSearchText: (text) => set({ searchText: text }),
setReplaceText: (text) => set({ replaceText: text }),
setMatches: (matches) => set({ matches, currentIndex: matches.length > 0 ? 0 : -1 }),
setCurrentIndex: (index) => set({ currentIndex: index }),
toggleCaseSensitive: () =>
set(state => ({ options: { ...state.options, caseSensitive: !state.options.caseSensitive } })),
toggleRegex: () =>
set(state => ({ options: { ...state.options, useRegex: !state.options.useRegex } })),
findNext: () => {
const { matches, currentIndex } = get()
if (matches.length === 0) return
set({ currentIndex: (currentIndex + 1) % matches.length })
},
findPrev: () => {
const { matches, currentIndex } = get()
if (matches.length === 0) return
set({ currentIndex: (currentIndex - 1 + matches.length) % matches.length })
},
close: () =>
set({
isVisible: false,
showReplace: false,
searchText: '',
replaceText: '',
matches: [],
currentIndex: -1
})
}))