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
+3 -13
View File
@@ -1,6 +1,5 @@
import React, { useEffect, useCallback } from 'react'
import { useTabStore } from '../../stores/tabStore'
import { useSearchStore } from '../../stores/searchStore'
import { useCodeMirror } from './useCodeMirror'
import { EditorToolbar } from './EditorToolbar'
@@ -20,12 +19,10 @@ export function Editor({ darkMode }: EditorProps) {
containerRef,
viewRef,
setContent,
getContent,
getScrollTop,
setScrollTop,
getSelection,
setSelection,
scrollTo
setSelection
} = useCodeMirror({
content: activeTab?.content ?? '',
onChange: useCallback((value: string) => {
@@ -43,15 +40,13 @@ export function Editor({ darkMode }: EditorProps) {
useEffect(() => {
if (!activeTab) return
setContent(activeTab.content)
// 恢复滚动和选区
requestAnimationFrame(() => {
setScrollTop(activeTab.scrollTop)
setSelection(activeTab.selectionStart, activeTab.selectionEnd)
})
}, [activeTabId])
// 保存当前标签状态(切换前)
// 保存当前标签状态
useEffect(() => {
return () => {
if (!activeTabId) return
@@ -63,12 +58,10 @@ export function Editor({ darkMode }: EditorProps) {
}
}, [activeTabId])
// 搜索:Ctrl+F 聚焦搜索框,Enter 导航
// Ctrl+B 粗体, Ctrl+I 斜体
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
const isCtrl = e.ctrlKey || e.metaKey
// Ctrl+B 粗体
if (isCtrl && e.key === 'b') {
e.preventDefault()
const view = viewRef.current
@@ -80,8 +73,6 @@ export function Editor({ darkMode }: EditorProps) {
selection: { anchor: from + 2, head: from + 2 + selected.length }
})
}
// Ctrl+I 斜体
if (isCtrl && e.key === 'i') {
e.preventDefault()
const view = viewRef.current
@@ -94,7 +85,6 @@ export function Editor({ darkMode }: EditorProps) {
})
}
}
document.addEventListener('keydown', handleKeyDown)
return () => document.removeEventListener('keydown', handleKeyDown)
}, [viewRef])