✨ feat(vscode): 代码阅读预览问 AI 的回答里代码位置写成链接、点了能跳:提示词要求写 [名字](路径#符号) 或 [文件名:起-止](路径#L起-L止) 并给出仓库根,仓库链接认 #L 行号(注释里同一套),旧回答里整段是「路径:行」的行内代码也当链接,带行号的在预览里展开、闪包住那几行的块,不支持预览的用文本编辑器选中
This commit is contained in:
1 parent
ceeaad91a7
commit
e401e4aec3
22 files changed
+516
-90
No files matched your search
@@ -3,7 +3,7 @@ import { useLayoutEffect } from 'react'
|
||||
import { blockPath } from './filter'
|
||||
import { pageLayout } from './pageLayout'
|
||||
import { placementOf } from './placement'
|
||||
import { revealPlan, scrollTopToShow, uncoveredPlan } from './reveal'
|
||||
import { linesPlan, revealPlan, scrollTopToShow, uncoveredPlan } from './reveal'
|
||||
import { scrollOwner } from './scrollOwner'
|
||||
import { stickyHeight } from './stickyScroll'
|
||||
|
||||
@@ -53,11 +53,12 @@ function nameAt(block: HTMLElement, offset: number): HTMLElement | null {
|
||||
|
||||
/**
|
||||
* 滚到 reveal 指的位置,处理完调 done:
|
||||
* ① 从文本编辑器切过来(没有 definition):包含那一行的块顶到视口顶部(筛选栏下面),折叠着的、被筛掉的不展开;
|
||||
* ① 从文本编辑器切过来(没有 definition,也没有 endLine):包含那一行的块顶到视口顶部(筛选栏下面),折叠着的、被筛掉的不展开;
|
||||
* ② 跳到定义:目标或它的祖先块被筛掉了,先临时露出这条路径(show);再展开把目标折叠住的块、属性行和子行(expand)——
|
||||
* 每一步之后重新渲染、再进来一次;最后把目标滚进筛选栏下面并闪几下。
|
||||
* 属性行 / 子行是这处定义时闪那一行;这块里显示着这个名字(下标盖住定义处)就闪这个名字,不闪整张卡片;
|
||||
* 名字不在页面上才闪整块。目标被正在编辑的祖先盖住时闪那个祖先(uncoveredPlan)。
|
||||
* ③ 跳到几行(有 endLine,点了带 `#L起-L止` 的链接):目标是包住这几行的块(见 [linesPlan]),露出、展开、滚过去同 ②,闪整块。
|
||||
* 滚过去以后由 [scrollOwner] 跟住目标(① 跟住那块),页面再长高(注释里的图画出来、中文名到了)也停在原处。
|
||||
*/
|
||||
export function useReveal(
|
||||
@@ -73,8 +74,8 @@ export function useReveal(
|
||||
useLayoutEffect(() => {
|
||||
if (!doc || !reveal)
|
||||
return
|
||||
const { line, definition } = reveal
|
||||
if (definition === undefined) {
|
||||
const { line, definition, endLine } = reveal
|
||||
if (definition === undefined && endLine === undefined) {
|
||||
const card = pageLayout.cardForLine(line)
|
||||
if (card)
|
||||
scrollOwner.align({ line: card.line, offset: 0, scrollTop: card.top })
|
||||
@@ -82,7 +83,7 @@ export function useReveal(
|
||||
return
|
||||
}
|
||||
const placement = placementOf(doc.blocks)
|
||||
const found = revealPlan(doc.blocks, placement, line, definition)
|
||||
const found = definition === undefined ? linesPlan(doc.blocks, placement, line, endLine ?? line) : revealPlan(doc.blocks, placement, line, definition)
|
||||
const plan = found && uncoveredPlan(found, covered)
|
||||
const path = plan ? blockPath(plan.id) : []
|
||||
if (path.some(id => filtered.has(id))) {
|
||||
@@ -99,7 +100,7 @@ export function useReveal(
|
||||
const locate = (): HTMLElement | null => {
|
||||
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 || base === undefined ? null : nameAt(block, definition - base)
|
||||
const name = row || !block || base === undefined || definition === undefined ? null : nameAt(block, definition - base)
|
||||
return row ?? name ?? block
|
||||
}
|
||||
const el = locate()
|
||||
|
||||
Reference in new issue
Block a user