From 4e21176a504eae7bd75af6b0aa4adf887302a7e1 Mon Sep 17 00:00:00 2001 From: Qijun Date: Mon, 26 Oct 2026 04:01:10 -0700 Subject: [PATCH] fix: a footnote's back link says where it goes, and the merged-block check on sheet_read stands as its own test --- ui-packages/web/src/components/markdown.tsx | 8 ++++++-- .../web/src/features/assistant/xlsx/tools.test.ts | 12 +++++++----- .../reader/markdown-reader/file-link.test.tsx | 2 +- .../features/reader/markdown-reader/file-link.tsx | 11 ++++++++--- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/ui-packages/web/src/components/markdown.tsx b/ui-packages/web/src/components/markdown.tsx index 17ab15d..af5fe2a 100644 --- a/ui-packages/web/src/components/markdown.tsx +++ b/ui-packages/web/src/components/markdown.tsx @@ -50,6 +50,7 @@ type MarkdownVariant = 'reader' | 'chat' export type MarkdownAnchorProps = { href?: string id?: string + 'aria-label'?: string children?: ReactNode variant: MarkdownVariant } @@ -57,6 +58,7 @@ export type MarkdownAnchorProps = { export const MarkdownAnchor = ({ href, id, + 'aria-label': label, children, variant, }: MarkdownAnchorProps): ReactElement => { @@ -66,6 +68,8 @@ export const MarkdownAnchor = ({ // A footnote links back to its reference by this id. Only the reader follows # links, and // chat messages would repeat the same footnote ids. id={variant === 'reader' ? id : undefined} + // A footnote's back link is a bare arrow; its label says where it goes. + aria-label={label} href={fragment || /^https?:\/\//.test(href ?? '') ? href : undefined} target={fragment ? undefined : '_blank'} rel="noopener noreferrer" @@ -82,8 +86,8 @@ const createComponents = (variant: MarkdownVariant, images?: MarkdownImageContex if (!images || !src) return {fallback} return }, - a: ({ href, id, children }) => ( - + a: ({ href, id, 'aria-label': label, children }) => ( + {children} ), diff --git a/ui-packages/web/src/features/assistant/xlsx/tools.test.ts b/ui-packages/web/src/features/assistant/xlsx/tools.test.ts index 2fc9b76..f26bf62 100644 --- a/ui-packages/web/src/features/assistant/xlsx/tools.test.ts +++ b/ui-packages/web/src/features/assistant/xlsx/tools.test.ts @@ -57,14 +57,16 @@ describe('sheet_read', () => { const byNumber = await call(workbook, 'sheet_read', { fileId: 'f', sheet: '2' }) expect(byName).toEqual(byNumber) expect(byName.sheet).toBe('汇总') - // A block the rows touch is named, so a value is read as covering all of it. - expect(byName.merged).toEqual(['A1:B1']) - expect( - await call(workbook, 'sheet_read', { fileId: 'f', sheet: '汇总', range: 'C1' }), - ).not.toHaveProperty('merged') expect((await call(workbook, 'sheet_read', { fileId: 'f' })).sheet).toBe('数据') }) + it('names the merged blocks the rows touch, whose value covers all of them', async () => { + const touching = await call(workbook, 'sheet_read', { fileId: 'f', sheet: '汇总', range: 'B1' }) + expect(touching.merged).toEqual(['A1:B1']) + const apart = await call(workbook, 'sheet_read', { fileId: 'f', sheet: '汇总', range: 'C1' }) + expect(apart).not.toHaveProperty('merged') + }) + it('refuses a range it cannot read rather than guessing one', async () => { await expect(call(workbook, 'sheet_read', { fileId: 'f', range: 'sheet1!A1' })).rejects.toThrow( /A1 notation/, diff --git a/ui-packages/web/src/features/reader/markdown-reader/file-link.test.tsx b/ui-packages/web/src/features/reader/markdown-reader/file-link.test.tsx index 2b1decf..c771ba6 100644 --- a/ui-packages/web/src/features/reader/markdown-reader/file-link.test.tsx +++ b/ui-packages/web/src/features/reader/markdown-reader/file-link.test.tsx @@ -107,7 +107,7 @@ describe('Markdown file links', () => { it('links a footnote back to the reference that cites it', () => { const { container } = show('Claim[^1].\n\n[^1]: Note.') - const back = screen.getByRole('link', { name: '↩' }) + const back = screen.getByRole('link', { name: 'Back to reference 1' }) const target = container.querySelector(`[id="${back.getAttribute('href')?.slice(1)}"]`) expect(target).toBe(screen.getByRole('link', { name: '1' })) }) diff --git a/ui-packages/web/src/features/reader/markdown-reader/file-link.tsx b/ui-packages/web/src/features/reader/markdown-reader/file-link.tsx index 6e54040..09d8b55 100644 --- a/ui-packages/web/src/features/reader/markdown-reader/file-link.tsx +++ b/ui-packages/web/src/features/reader/markdown-reader/file-link.tsx @@ -5,14 +5,19 @@ import { resolveFileReferencePath } from '../../../utils/file-reference' import { useOpenFile } from '../../workspace/workspace-context' import { useEmbedScope } from './embed-context' -export type FileLinkProps = Pick, 'href' | 'id' | 'children'> +export type FileLinkProps = Pick, 'href' | 'id' | 'aria-label' | 'children'> -export const FileLink = ({ href, id, children }: FileLinkProps): ReactElement => { +export const FileLink = ({ + href, + id, + 'aria-label': label, + children, +}: FileLinkProps): ReactElement => { const scope = useEmbedScope() const openFile = useOpenFile() if (!scope || !href || /^(?:[a-z][a-z\d+.-]*:|#|\/\/)/i.test(href.trim())) return ( - + {children} )