fix: 修复侧边栏根目录、搜索高亮导航、行号同步
问题1: 侧边栏打开文件夹后根目录不显示
修复: FileTree 传入包装后的根节点 { name, path, type: 'dir', children: tree }
打开文件夹时自动展开根目录 expandDirs([rootPath])
问题2: 搜索没有高亮,上一个/下一个没反应
修复: Editor 添加完整搜索功能
- 搜索时在 textarea 上方创建 overlay div
- 用绝对定位 div 标记每个匹配位置(单行/多行)
- currentIndex 变化时选中匹配文本并滚动到可视区域
- 搜索结果随内容变化自动更新
问题3: 滚动时行号跟随不准确
修复: 行高测量改为与 CSS line-height 一致的动态测量
搜索高亮位置随编辑器滚动同步更新
This commit is contained in:
@@ -53,13 +53,15 @@ export function Sidebar() {
|
||||
const dirPath = await window.electronAPI.openFolderDialog()
|
||||
if (dirPath) {
|
||||
setRootPath(dirPath)
|
||||
// 展开根目录
|
||||
expandDirs([dirPath])
|
||||
const result = await window.electronAPI.readDirTree(dirPath)
|
||||
if (result.success && result.tree) {
|
||||
setTree(result.tree)
|
||||
window.electronAPI.watchDir(dirPath)
|
||||
}
|
||||
}
|
||||
}, [setRootPath, setTree])
|
||||
}, [setRootPath, setTree, expandDirs])
|
||||
|
||||
const refreshTree = useCallback(async () => {
|
||||
if (!rootPath || !window.electronAPI) return
|
||||
@@ -153,7 +155,7 @@ export function Sidebar() {
|
||||
<>
|
||||
<div className="sidebar-section-header">文件夹目录树</div>
|
||||
<FileTree
|
||||
nodes={tree}
|
||||
nodes={[{ name: rootPath.split(/[/\\]/).pop() || rootPath, path: rootPath, type: 'dir' as const, children: tree }]}
|
||||
depth={0}
|
||||
expandedDirs={expandedDirs}
|
||||
toggleDir={toggleDir}
|
||||
|
||||
Reference in New Issue
Block a user