fix(outline): hover 高亮残留——内联 onMouseEnter/onMouseLeave 用 if(i!==activeIdx) 条件, 点击后 activeIdx 变化导致 onMouseLeave 条件为 false 不清除背景. 改用纯 CSS :hover 替代内联 JS, 浏览器自动管理 hover 状态无竞态

This commit is contained in:
hunter-dev
2026-08-26 22:05:33 +08:00
parent a18982659b
commit 7f48cef344
2 changed files with 4 additions and 5 deletions
@@ -109,10 +109,8 @@ export function OutlinePanel() {
{headings.map((h, i) => (
<div key={h.id} data-idx={i} onClick={() => scrollTo(h)}
className={i === activeIdx ? 'outline-item outline-item-active' : 'outline-item'}
style={{ paddingLeft: 8 + (h.level - 1) * 12, cursor: 'pointer', padding: '4px 4px 4px ' + (8 + (h.level-1)*12) + 'px',
fontSize: 13, borderRadius: 4 }}
onMouseEnter={e => { if (i !== activeIdx) e.currentTarget.style.background = 'var(--control-border)'; }}
onMouseLeave={e => { if (i !== activeIdx) e.currentTarget.style.background = 'transparent'; }}>
style={{ cursor: 'pointer', padding: '4px 4px 4px ' + (8 + (h.level-1)*12) + 'px',
fontSize: 13, borderRadius: 4 }}>
{h.text || '(空标题)'}
</div>
))}
+2 -1
View File
@@ -74,7 +74,8 @@ html, body, #root { margin: 0; height: 100%; }
border-radius: 4px;
}
/* FR-O3:大纲当前项高亮——主题变量适配 */
/* FR-O3:大纲项 hover + 当前项高亮——用 CSS :hover 避免内联 style 竞态 */
.outline-item:hover { background: var(--control-border); }
.outline-item-active {
background: var(--control-border) !important;
border-left: 2px solid var(--accent) !important;