⚡ perf(vscode): 代码阅读预览发给页面的块只记相对位置:块在源码里占的地方记成离前一块多远、自己多长,块里名字的下标从块的开头算,页面从文件开头累加回文件里的位置、和扩展端打交道的地方都在一处换算;靠前改了代码,后面内容没变的块发过去一模一样,扩展端自己的块和发给页面的块分成两种类型
This commit is contained in:
1 parent
3a2815c19c
commit
ad5f559e92
43 files changed
+980
-424
No files matched your search
@@ -3,6 +3,7 @@ import type { DocumentMessage, Reveal } from './types'
|
||||
import { useLayoutEffect } from 'react'
|
||||
import { blockPath } from './filter'
|
||||
import { pageLayout } from './pageLayout'
|
||||
import { placementOf } from './placement'
|
||||
import { revealPlan, scrollTopToShow, uncoveredPlan } from './reveal'
|
||||
import { stickyHeight } from './useStickyScroll'
|
||||
|
||||
@@ -44,7 +45,7 @@ export function showInViewport(el: HTMLElement, beforeScroll?: (position: Scroll
|
||||
window.scrollTo(position.x, position.y)
|
||||
}
|
||||
|
||||
/** 这块自己显示着的、下标就是定义处的那个名字。子块里的同名下标不算,免得闪到旁边那张卡片。 */
|
||||
/** 这块自己显示着的、下标(块里的)就是定义处的那个名字。子块里的同名下标不算,免得闪到旁边那张卡片。 */
|
||||
function nameAt(block: HTMLElement, offset: number): HTMLElement | null {
|
||||
for (const el of block.querySelectorAll<HTMLElement>('[data-offset]')) {
|
||||
if (Number(el.dataset.offset) !== offset)
|
||||
@@ -83,7 +84,8 @@ export function useReveal(
|
||||
done()
|
||||
return
|
||||
}
|
||||
const found = revealPlan(doc.blocks, reveal.line, reveal.definition)
|
||||
const placement = placementOf(doc.blocks)
|
||||
const found = revealPlan(doc.blocks, placement, reveal.line, reveal.definition)
|
||||
const plan = found && uncoveredPlan(found, covered)
|
||||
const path = plan ? blockPath(plan.id) : []
|
||||
if (path.some(id => filtered.has(id))) {
|
||||
@@ -98,7 +100,8 @@ export function useReveal(
|
||||
// 块正在编辑时页面上没有属性表,就闪整块
|
||||
const block = plan ? document.querySelector<HTMLElement>(`.cr-block[data-id="${plan.id}"]`) : null
|
||||
const row = plan?.row === undefined ? null : document.querySelector<HTMLElement>(`:is(.cr-prop-row, .cr-prop-item, .cr-table-row)[data-id="${plan.row}"]`)
|
||||
const name = row || !block ? null : nameAt(block, reveal.definition)
|
||||
const base = plan && placement.of(plan.id)?.offset
|
||||
const name = row || !block || base === undefined ? null : nameAt(block, reveal.definition - base)
|
||||
const el = row ?? name ?? block
|
||||
if (el) {
|
||||
showInViewport(el)
|
||||
|
||||
Reference in new issue
Block a user