🐛 fix(vscode): 代码阅读预览跳到定义后页面还在长高(注释里的 mermaid 画成图、中文名到了)不再把视口带跑:页面滚动统一交给滚动所有者,跟住跳到的目标、用户自己滚了改钉视口顶部那块,关掉浏览器自带的滚动锚定
This commit is contained in:
1 parent
2fa6319dd4
commit
3c5f5f5f35
24 files changed
+1016
-149
No files matched your search
@@ -3,6 +3,7 @@ import type { BlockView, StickyScrollSettings } from './types'
|
||||
import { useContext, useLayoutEffect, useMemo } from 'react'
|
||||
import { KindIcon } from './kindIcons'
|
||||
import { pageLayout } from './pageLayout'
|
||||
import { scrollOwner } from './scrollOwner'
|
||||
import { BlockIdContext, SegmentText, TextMarksContext } from './SegmentText'
|
||||
import { selectStore } from './store'
|
||||
import { flash } from './useReveal'
|
||||
@@ -47,7 +48,7 @@ export function PinnedHead({ block }: { block: BlockView }): ReactElement {
|
||||
* 钉在顶上的卡片(同 VS Code 编辑器的 Sticky Scroll,设置也用它的,一张卡片就是一层):卡片的开头已经滚到筛选栏后面、卡片(连同子块)
|
||||
* 还有一部分看得见时,筛选栏下面钉一行这张卡片的头(PinnedHead),外层的在上、里层的往下摞,每行和那张卡片左右对齐(越里层越往右);
|
||||
* 这张卡片快滚完时,最里那行被下面的内容顶上去、从上一行下面滑走。哪几张见 pinnedLines,只按页面上画出来的算:
|
||||
* 折叠着的卡片自己照样钉(它的子块没画出来,不算);被筛掉的不在页面上,正在编辑的不钉。点一行把那张卡片滚到顶上(外层还钉着的几行下面)、闪几下。
|
||||
* 折叠着的卡片自己照样钉(它的子块没画出来,不算);被筛掉的不在页面上,正在编辑的不钉。点一行把那张卡片滚到顶上(外层还钉着的几行下面,之后由 [scrollOwner] 跟住)、闪几下。
|
||||
* 钉着的名字不画页面上的高亮(页面上找当前那一处只认卡片里的);跳到定义、悬停看卡片照旧。
|
||||
* content 是块树所在的页面内容,blocks 是这份文档的块。
|
||||
*/
|
||||
@@ -74,11 +75,13 @@ export function StickyLines({ content, blocks, settings }: { content: RefObject<
|
||||
return null
|
||||
|
||||
const jump = (id: string): void => {
|
||||
const card = content.current?.querySelector<HTMLElement>(`.cr-block[data-id="${id}"]`)
|
||||
const locate = (): HTMLElement | null => content.current?.querySelector<HTMLElement>(`.cr-block[data-id="${id}"]`) ?? null
|
||||
const card = locate()
|
||||
if (!card)
|
||||
return
|
||||
pageLayout.settle(card)
|
||||
window.scrollTo(0, card.getBoundingClientRect().top + window.scrollY - pageLayout.pinnedHeight() - stickyInset(card, settings))
|
||||
const inset = pageLayout.pinnedHeight() + stickyInset(card, settings)
|
||||
scrollOwner.reveal(locate, box => box.top - inset)
|
||||
flash(card)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user