BLock Editor大纲导航栏向下滚动时增加固定效果

This commit is contained in:
jingrow 2026-06-02 03:25:05 +08:00
parent 405267b026
commit c4b242e01f
2 changed files with 27 additions and 10 deletions

View File

@ -1055,7 +1055,7 @@ function icon(name: string): string {
.blockeditor-outline-rail-wrapper {
position: absolute;
right: 6px;
top: 48px; /* 工具栏下方 */
top: 100px; /* 相对工具栏 100px */
bottom: 12px;
width: 24px;
overflow: visible;
@ -1063,6 +1063,15 @@ function icon(name: string): string {
z-index: 10;
}
/* 工具栏固定时,大纲导航栏同步固定到容器右侧 */
.blockeditor-container .n-affix--affixed ~ .blockeditor-outline-rail-wrapper {
position: fixed;
top: calc(64px + 100px); /* header + 相对工具栏 100px */
bottom: 12px;
left: calc(var(--be-container-left) + var(--be-container-width) - 30px);
right: auto;
}
/* ── ProseMirror ── */
.blockeditor-mount .ProseMirror { outline: none; min-height: 120px; padding-left: 48px; padding-right: 36px; }
.blockeditor-mount .ProseMirror > * + * { margin-top: 0.5em; }

View File

@ -159,13 +159,21 @@ function syncActive() {
}
// Helpers
/** 获取页面导航栏底部位置(即内容区顶部在视口中的 y 坐标) */
/** y
* 工具栏固定时自动计入工具栏高度确保内容不被遮挡 */
function getContentTop(): number {
const header = document.querySelector('.n-layout-header')
if (header) {
return header.getBoundingClientRect().bottom
let top = header ? header.getBoundingClientRect().bottom : 64
//
const affixedToolbar = document.querySelector(
'.blockeditor-container .n-affix--affixed .blockeditor-toolbar'
)
if (affixedToolbar) {
top += affixedToolbar.getBoundingClientRect().height
}
return 64 // fallback: AppHeader 64px
return top
}
/** 向上查找真正可滚动的祖先容器 */
@ -262,12 +270,12 @@ function scrollToBlock(block: BlockInfo) {
const { view } = props.editor
// ProseMirror transaction: heading
view.dispatch(
view.state.tr.setSelection(
TextSelection.create(view.state.doc, block.pos + 1),
),
// ProseMirror transaction: heading
const tr = view.state.tr.setSelection(
TextSelection.create(view.state.doc, block.pos + 1),
)
tr.scrollIntoView = false
view.dispatch(tr)
//
const domNode = view.nodeDOM(block.pos)