v0.3.6: 修复文档大纲导航Bug + 新增自动保存功能
Bug修复:
- 文档大纲点击标题未定位到编辑器内容 (P0)
- 根因: raw markdown字符偏移 ≠ ProseMirror文档位置
- 改为通过 view.state.doc.descendants() 遍历节点树,
按 heading类型名 + level + textContent 三重匹配定位
新增功能:
- 自动保存 (2秒防抖), 仅对文件标签页生效
- 状态栏显示 自动/保存中... 指示器
版本同步: package.json / AboutDialog / README 均更新至 v0.3.6
This commit is contained in:
@@ -36,25 +36,27 @@ export function parseHeadings(markdown: string): Heading[] {
|
||||
|
||||
interface OutlinePanelProps {
|
||||
headings: Heading[]
|
||||
onNavigate: (pos: number) => void
|
||||
onNavigate: (heading: Heading, index: number) => void
|
||||
activeHeadingIndex: number | null
|
||||
}
|
||||
|
||||
interface OutlineItemProps {
|
||||
heading: Heading
|
||||
index: number
|
||||
isActive: boolean
|
||||
onNavigate: (pos: number) => void
|
||||
onNavigate: (heading: Heading, index: number) => void
|
||||
}
|
||||
|
||||
const OutlineItem = memo(function OutlineItem({
|
||||
heading,
|
||||
index,
|
||||
isActive,
|
||||
onNavigate
|
||||
}: OutlineItemProps) {
|
||||
return (
|
||||
<button
|
||||
className={`outline-item outline-level-${heading.level}${isActive ? ' active' : ''}`}
|
||||
onClick={() => onNavigate(heading.pos)}
|
||||
onClick={() => onNavigate(heading, index)}
|
||||
title={heading.text}
|
||||
aria-label={`跳转到标题:${heading.text}`}
|
||||
style={{ paddingLeft: `${8 + (heading.level - 1) * 12}px` }}
|
||||
@@ -85,8 +87,9 @@ export const OutlinePanel = memo(function OutlinePanel({
|
||||
<div className="outline-list" role="list" aria-label="标题列表">
|
||||
{headings.map((h, i) => (
|
||||
<OutlineItem
|
||||
key={`${h.text}-${h.pos}`}
|
||||
key={`${h.text}-${i}`}
|
||||
heading={h}
|
||||
index={i}
|
||||
isActive={i === activeHeadingIndex}
|
||||
onNavigate={onNavigate}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user