mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-17 13:13:35 +08:00
fix(desktop): selection回填只留用户意见+圈选截图,去掉selector/DOM/页面噪音
圈选标注截图作为引用承载元素位置;输入框文字只放用户修改意见+具体改动(人话), 不再写 selector/nthPath/computedStyles/页面URL/「请在源码中落地」。沿用进输入框+手动发送。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
81ed3e2530
commit
ca2de74f87
@ -32,7 +32,7 @@ describe('subscribePreviewEvents', () => {
|
||||
const payload = { pageUrl: 'http://x/', element: { selector: '#t', tag: 'h1', classes: [] }, change: { description: '改一下' }, screenshot: { dataUrl: 'data:image/png;base64,AAAA', kind: 'element' } }
|
||||
listeners['preview://event']!({ payload: JSON.stringify({ v: 1, type: 'selection', payload }) })
|
||||
expect(prefill).toHaveBeenCalledWith('s1', expect.objectContaining({
|
||||
text: expect.stringContaining('#t'),
|
||||
text: expect.stringContaining('改一下'),
|
||||
attachments: [expect.objectContaining({ type: 'image', data: 'data:image/png;base64,AAAA' })],
|
||||
}))
|
||||
})
|
||||
|
||||
@ -1,15 +1,26 @@
|
||||
import { expect, it } from 'vitest'
|
||||
import { buildSelectionComposerText } from './selectionComposer'
|
||||
|
||||
it('renders a readable block with locator + change + source', () => {
|
||||
it('renders only the user instruction + concrete changes (no selector/DOM/page noise)', () => {
|
||||
const text = buildSelectionComposerText({
|
||||
pageUrl: 'http://127.0.0.1:4321/preview-fs/s1/index.html',
|
||||
sourceHint: 'index.html',
|
||||
element: { selector: '#title', tag: 'h1', text: '模型还没用熟', classes: [] } as never,
|
||||
change: { text: { from: '模型还没用熟', to: '模型用熟了' }, description: '标题改积极一点' } as never,
|
||||
})
|
||||
expect(text).toContain('#title')
|
||||
expect(text).toContain('index.html')
|
||||
expect(text).toContain('模型用熟了')
|
||||
// 用户的话 + 具体改动在
|
||||
expect(text).toContain('标题改积极一点')
|
||||
expect(text).toContain('模型用熟了')
|
||||
// selector / 页面 URL / 「请在源码中落地」 等 DOM 噪音不在(截图才是引用)
|
||||
expect(text).not.toContain('#title')
|
||||
expect(text).not.toContain('index.html')
|
||||
expect(text).not.toContain('请在源码中落地')
|
||||
})
|
||||
|
||||
it('returns empty text when there is no description or change (image alone is the reference)', () => {
|
||||
const text = buildSelectionComposerText({
|
||||
pageUrl: 'http://x/',
|
||||
element: { selector: '#t', tag: 'div', classes: [] } as never,
|
||||
})
|
||||
expect(text).toBe('')
|
||||
})
|
||||
|
||||
@ -7,18 +7,20 @@ export type SelectionPayload = {
|
||||
change?: EditDiff & { description?: string }
|
||||
}
|
||||
|
||||
/**
|
||||
* 选中元素的「引用」由随附的圈选标注截图承载(截图里已把元素圈出来)。
|
||||
* 这里只产出用户的修改意见 + 具体改动(人话),**不再**把 selector / DOM 定位 /
|
||||
* computedStyles / 页面 URL 等写进输入框 —— 那些 DOM 噪音交互体验差,且图片已是引用。
|
||||
* 无描述、无改动时返回空串(让图片单独作为引用进输入框)。
|
||||
*/
|
||||
export function buildSelectionComposerText(p: SelectionPayload): string {
|
||||
const lines: string[] = []
|
||||
lines.push(`针对页面元素 \`${p.element.selector}\`(${p.element.tag}${p.element.text ? `,文本「${p.element.text}」` : ''}):`)
|
||||
if (p.sourceHint) lines.push(`- 来源:${p.sourceHint}`)
|
||||
lines.push(`- 页面:${p.pageUrl}`)
|
||||
const c = p.change
|
||||
const lines: string[] = []
|
||||
if (c?.description) lines.push(c.description)
|
||||
if (c?.text) lines.push(`- 文本:「${c.text.from}」→「${c.text.to}」`)
|
||||
if (c?.color) lines.push(`- 文字颜色:${c.color.from} → ${c.color.to}`)
|
||||
if (c?.background) lines.push(`- 背景:${c.background.from} → ${c.background.to}`)
|
||||
if (c?.opacity) lines.push(`- 不透明度:${c.opacity.from} → ${c.opacity.to}`)
|
||||
if (c?.fontFamily) lines.push(`- 字体:${c.fontFamily.from} → ${c.fontFamily.to}`)
|
||||
if (c?.description) lines.push(`- 说明:${c.description}`)
|
||||
lines.push('请在源码中落地以上修改。')
|
||||
return lines.join('\n')
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user