feat(annotate): 指哪打哪标注 MVP——窗格折叠键旁标注按钮 → 蓝色冒泡光标 → 点击弹输入框(✓/✕) → 打包(窗口N+屏幕/窗口内坐标+元素上下文+要求)注入宿主输入框不发送,失败回退剪贴板
This commit is contained in:
@@ -181,6 +181,10 @@ export const zh = {
|
||||
'pane.termFail': '终端不可用(宿主缺少 node-pty/ws 或连接失败)',
|
||||
'pane.closeTab': '关闭标签页',
|
||||
'pane.collapse': '折叠窗格',
|
||||
'annot.label': '标注:点击窗口中的位置提要求',
|
||||
'annot.placeholder': '对这里提要求…(Enter 确认,Shift+Enter 换行,Esc 取消)',
|
||||
'annot.ok': '确认:注入对话框输入框(不发送)',
|
||||
'annot.cancel': '取消',
|
||||
'pane.expand': '展开窗格',
|
||||
'pane.jobsTitle': '后台任务',
|
||||
'pane.subagents': '子代理',
|
||||
@@ -386,6 +390,10 @@ export const en = {
|
||||
'pane.termFail': 'Terminal unavailable (host missing node-pty/ws, or connection failed)',
|
||||
'pane.closeTab': 'Close tab',
|
||||
'pane.collapse': 'Collapse pane',
|
||||
'annot.label': 'Annotate: click a spot in the window',
|
||||
'annot.placeholder': 'Describe what to change here… (Enter to confirm, Shift+Enter newline, Esc cancel)',
|
||||
'annot.ok': 'Confirm: put into chat input (not sent)',
|
||||
'annot.cancel': 'Cancel',
|
||||
'pane.expand': 'Expand pane',
|
||||
'pane.jobsTitle': 'Background jobs',
|
||||
'pane.subagents': 'Subagents',
|
||||
|
||||
@@ -295,6 +295,162 @@ function setDropTarget(t: { row: PaneRow; index: number } | null) {
|
||||
for (const fn of dropTargetListeners) fn()
|
||||
}
|
||||
|
||||
/** ——「指哪打哪」标注引擎:按钮 → 蓝色冒泡光标 → 点击弹输入框 → ✓ 打包进对话框(不发送) —— */
|
||||
type AnnotState = {
|
||||
on: boolean
|
||||
started: boolean
|
||||
px: number
|
||||
py: number
|
||||
ex: number
|
||||
ey: number
|
||||
draft: string
|
||||
resp: string
|
||||
stat: string
|
||||
}
|
||||
let annotState: AnnotState = { on: false, started: false, px: 0, py: 0, ex: 0, ey: 0, draft: '', resp: '', stat: '' }
|
||||
const annotListeners = new Set<() => void>()
|
||||
function setAnnot(patch: Partial<AnnotState>) {
|
||||
annotState = { ...annotState, ...patch }
|
||||
for (const fn of annotListeners) fn()
|
||||
}
|
||||
function subscribeAnnot(fn: () => void) { annotListeners.add(fn); return () => { annotListeners.delete(fn) } }
|
||||
|
||||
/** 进入瞄准模式(resp = 窗口编号等上下文,由调用方拼好) */
|
||||
function startAnnot(resp: string) {
|
||||
document.body.classList.add('dsh-wt-annotating')
|
||||
setAnnot({ on: true, started: false, resp, stat: '', draft: '' })
|
||||
}
|
||||
function cancelAnnot() {
|
||||
document.body.classList.remove('dsh-wt-annotating')
|
||||
setAnnot({ on: false, started: false })
|
||||
}
|
||||
|
||||
/** 窗口编号(约定:左栏 → 顶行 → 主行,从 1 起) */
|
||||
function windowLabelOf(row: PaneRow, index: number): string {
|
||||
const spec = splitStore.spec
|
||||
if (!spec) return '窗口?'
|
||||
let num = spec.left ? 2 : 1
|
||||
if (row === 'left') return '窗口1'
|
||||
if (row === 'top') return '窗口' + (num + index)
|
||||
num += (spec.top?.length ?? 0)
|
||||
return '窗口' + (num + index)
|
||||
}
|
||||
|
||||
/** 被点元素上下文(标签 + 类名 + 文字) */
|
||||
function ctxOf(t: EventTarget | null): string {
|
||||
const el = t instanceof Element ? t : null
|
||||
if (!el || el === document.documentElement || el === document.body) return ''
|
||||
const tag = el.tagName.toLowerCase()
|
||||
const cls = (el.getAttribute('class') || '').split(/\s+/).filter(Boolean).slice(0, 4).join('.')
|
||||
const text = (el.textContent || '').trim().replace(/\s+/g, ' ').slice(0, 60)
|
||||
let out = '<' + tag + (cls ? ' .' + cls : '') + '>'
|
||||
if (text) out += '「' + text + '」'
|
||||
return out
|
||||
}
|
||||
|
||||
/** 注入宿主对话框输入框(不发送);失败返回 false */
|
||||
function fillHostInput(text: string): boolean {
|
||||
try {
|
||||
const ta = document.querySelector<HTMLTextAreaElement>('textarea[data-phase]')
|
||||
?? Array.from(document.querySelectorAll<HTMLTextAreaElement>('textarea')).pop()
|
||||
if (!ta) return false
|
||||
const setter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set
|
||||
if (setter) setter.call(ta, text)
|
||||
else ta.value = text
|
||||
ta.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
try {
|
||||
ta.focus()
|
||||
ta.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
ta.setSelectionRange(ta.value.length, ta.value.length)
|
||||
} catch {}
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** ✓ 确认:打包并注入,不发送 */
|
||||
function confirmAnnot() {
|
||||
const s = annotState
|
||||
const text = '📌 标注-' + s.resp + '\n' + (s.stat || '') + '\n要求:' + (s.draft.trim() || '(未填写)')
|
||||
const ok = fillHostInput(text)
|
||||
if (!ok) {
|
||||
try {
|
||||
navigator.clipboard?.writeText(text).catch(() => { try { window.prompt('标注已生成,请手动复制:', text) } catch {} })
|
||||
} catch {
|
||||
try { window.prompt('标注已生成,请手动复制:', text) } catch {}
|
||||
}
|
||||
}
|
||||
cancelAnnot()
|
||||
}
|
||||
|
||||
/** 标注浮层:瞄准气泡 + 输入编辑器(每个工作区渲染一次;fixed 定位) */
|
||||
function AnnotationOverlay() {
|
||||
const [, setTick] = useState(0)
|
||||
useEffect(() => subscribeAnnot(() => setTick((t) => t + 1)), [])
|
||||
const s = annotState
|
||||
useEffect(() => {
|
||||
if (!s.on || s.started) return
|
||||
const onMove = (e: MouseEvent) => { if (annotState.on && !annotState.started) setAnnot({ px: e.clientX, py: e.clientY }) }
|
||||
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') cancelAnnot() }
|
||||
const onClick = (e: MouseEvent) => {
|
||||
if (!annotState.on || annotState.started) return
|
||||
if (e.target instanceof Element && e.target.closest('.dsh-wt_annotUi')) return
|
||||
e.preventDefault()
|
||||
e.stopImmediatePropagation()
|
||||
const paneEl = (e.target instanceof Element ? e.target.closest('.dsh-wt_pane') : null) as HTMLElement | null
|
||||
let stat = '屏幕坐标 (' + Math.round(e.clientX) + ', ' + Math.round(e.clientY) + ')'
|
||||
if (paneEl) {
|
||||
const r = paneEl.getBoundingClientRect()
|
||||
const rx = (((e.clientX - r.left) / Math.max(1, r.width)) * 100).toFixed(1)
|
||||
const ry = (((e.clientY - r.top) / Math.max(1, r.height)) * 100).toFixed(1)
|
||||
stat += ',窗口内 (' + rx + '%, ' + ry + '%)'
|
||||
}
|
||||
const ctx = ctxOf(e.target)
|
||||
if (ctx) stat += ',元素 ' + ctx
|
||||
const ex = Math.max(8, Math.min(e.clientX + 10, window.innerWidth - 288))
|
||||
const ey = Math.max(8, Math.min(e.clientY + 14, window.innerHeight - 148))
|
||||
setAnnot({ started: true, ex, ey, stat })
|
||||
}
|
||||
window.addEventListener('mousemove', onMove, true)
|
||||
window.addEventListener('click', onClick, true)
|
||||
window.addEventListener('keydown', onKey, true)
|
||||
return () => {
|
||||
window.removeEventListener('mousemove', onMove, true)
|
||||
window.removeEventListener('click', onClick, true)
|
||||
window.removeEventListener('keydown', onKey, true)
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [s.on, s.started])
|
||||
if (!s.on) return null
|
||||
if (!s.started) {
|
||||
return (
|
||||
<div className="dsh-wt_annotUi dsh-wt_annotBubble" style={{ left: s.px, top: s.py }} aria-hidden>
|
||||
<svg width="12" height="12" viewBox="0 0 16 16"><path d="M8 3.2v9.6M3.2 8h9.6" fill="none" stroke="#fff" strokeWidth="1.8" strokeLinecap="round" /></svg>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<div className="dsh-wt_annotUi dsh-wt_annotEditor" style={{ left: s.ex, top: s.ey }}>
|
||||
<textarea
|
||||
className="dsh-wt_annotInput"
|
||||
autoFocus
|
||||
value={s.draft}
|
||||
placeholder={T('annot.placeholder')}
|
||||
onChange={(e) => setAnnot({ draft: e.target.value })}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); confirmAnnot() }
|
||||
if (e.key === 'Escape') cancelAnnot()
|
||||
}}
|
||||
/>
|
||||
<div className="dsh-wt_annotBtns">
|
||||
<button type="button" className="dsh-wt_annotOk" title={T('annot.ok')} aria-label={T('annot.ok')} onClick={confirmAnnot}>✓</button>
|
||||
<button type="button" className="dsh-wt_annotNo" title={T('annot.cancel')} aria-label={T('annot.cancel')} onClick={cancelAnnot}>✕</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** 找到会话根容器:data-phase 元素中排除输入框、取含子元素者;优先 phase=active;无活动会话返回 null */
|
||||
function findConversationRoot(): HTMLElement | null {
|
||||
const candidates = Array.from(document.querySelectorAll<HTMLElement>('[data-phase]'))
|
||||
@@ -2353,6 +2509,16 @@ function WorkspaceLayer(props: { spec: LayoutSpec; geom: Geom | null; chatW: num
|
||||
)}
|
||||
<PaneBody pane={it.pane} row={row} index={index} />
|
||||
{!singleConsole && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="dsh-wt_annotBtn"
|
||||
title={T('annot.label')}
|
||||
aria-label={T('annot.label')}
|
||||
onClick={() => startAnnot(windowLabelOf(row, index))}
|
||||
>
|
||||
<svg viewBox="0 0 16 16" aria-hidden><path d="M2 5.6c0-1.2 1-2.2 2.2-2.2h7.6c1.2 0 2.2 1 2.2 2.2v3.6c0 1.2-1 2.2-2.2 2.2H7.5L5 13.6l.3-2.4H4.2c-1.2 0-2.2-1-2.2-2.2z" fill="none" stroke="currentColor" strokeWidth="1.2" strokeLinejoin="round" /><path d="M8 5.3v3.4M6.3 7h3.4" fill="none" stroke="currentColor" strokeWidth="1.2" strokeLinecap="round" /></svg>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={'dsh-wt_collapseBtn' + (it.pane.collapsed ? ' dsh-wt_collapseBtnCollapsed' : '')}
|
||||
@@ -2366,6 +2532,7 @@ function WorkspaceLayer(props: { spec: LayoutSpec; geom: Geom | null; chatW: num
|
||||
<svg viewBox="0 0 16 16" aria-hidden><path d="M4 10l4-4 4 4" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" /></svg>
|
||||
)}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
@@ -2439,6 +2606,7 @@ function WorkspaceLayer(props: { spec: LayoutSpec; geom: Geom | null; chatW: num
|
||||
}}
|
||||
onPointerDown={makeDividerHandler(hasLeft ? 'left' : 'chat')}
|
||||
/>
|
||||
<AnnotationOverlay />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -148,6 +148,19 @@ export const css = xtermCss + '\n' + [
|
||||
'.dsh-wt_collapseBtn{position:absolute;top:2px;right:4px;z-index:2;width:18px;height:18px;margin:0;padding:0;display:flex;align-items:center;justify-content:center;border:1px solid transparent;border-radius:4px;background:transparent;color:var(--dsw-alias-label-tertiary,#6e7683);cursor:pointer}',
|
||||
'.dsh-wt_collapseBtn:hover{color:var(--dsw-alias-label-primary,#e6e8eb);background:var(--dsw-alias-fill-l2,rgba(255,255,255,.09));border-color:var(--dsw-alias-border-l1,#262b36)}',
|
||||
'.dsh-wt_collapseBtn svg{width:12px;height:12px;display:block}',
|
||||
'.dsh-wt_annotBtn{position:absolute;top:2px;right:26px;z-index:2;width:18px;height:18px;margin:0;padding:0;display:flex;align-items:center;justify-content:center;border:1px solid transparent;border-radius:4px;background:transparent;color:var(--dsw-alias-label-tertiary,#6e7683);cursor:pointer}',
|
||||
'.dsh-wt_annotBtn:hover{color:var(--dsw-alias-label-primary,#e6e8eb);background:var(--dsw-alias-fill-l2,rgba(255,255,255,.09));border-color:var(--dsw-alias-border-l1,#262b36)}',
|
||||
'.dsh-wt_annotBtn svg{width:12px;height:12px;display:block}',
|
||||
'.dsh-wt-annotating,.dsh-wt-annotating *{cursor:none!important}',
|
||||
'.dsh-wt_annotBubble{position:fixed;z-index:5000;left:0;top:0;transform:translate(-50%,-100%) translateY(-4px);pointer-events:none;width:30px;height:22px;border-radius:9px;background:#4f8ef7;box-shadow:0 2px 10px rgba(79,142,247,.5);display:flex;align-items:center;justify-content:center}',
|
||||
'.dsh-wt_annotBubble::after{content:"";position:absolute;left:50%;bottom:-5px;transform:translateX(-50%);border:6px solid #4f8ef7;border-top-width:5px;border-bottom-width:0;border-left-color:transparent;border-right-color:transparent}',
|
||||
'.dsh-wt_annotEditor{position:fixed;z-index:5001;width:280px;box-sizing:border-box;display:flex;flex-direction:column;gap:6px;padding:8px;border-radius:10px;background:rgba(16,20,28,.96);border:1px solid rgba(255,255,255,.2);box-shadow:0 10px 30px rgba(0,0,0,.5)}',
|
||||
'.dsh-wt_annotInput{width:100%;box-sizing:border-box;height:56px;padding:6px 8px;border:1px solid rgba(255,255,255,.18);border-radius:7px;background:rgba(255,255,255,.05);color:#e6e8eb;font:inherit;font-size:12px;line-height:17px;resize:none;outline:none;cursor:text}',
|
||||
'.dsh-wt_annotInput:focus{border-color:#4f8ef7}',
|
||||
'.dsh-wt_annotBtns{display:flex;justify-content:flex-end;gap:6px}',
|
||||
'.dsh-wt_annotOk,.dsh-wt_annotNo{flex:none;width:26px;height:22px;padding:0;border:none;border-radius:6px;background:rgba(255,255,255,.08);color:var(--dsw-alias-label-primary,#e6e8eb);font-size:12px;line-height:1;cursor:pointer;display:inline-flex;align-items:center;justify-content:center}',
|
||||
'.dsh-wt_annotOk:hover{background:#1d9a55;color:#fff}',
|
||||
'.dsh-wt_annotNo:hover{background:#c0392b;color:#fff}',
|
||||
'.dsh-wt_collapseBtnCollapsed{color:var(--dsw-alias-label-secondary,#9aa4b2)}',
|
||||
'.dsh-wt_paneFrame{flex:1;width:100%;border:0;background:#010409;min-height:0}',
|
||||
// iframe 内容标签:容器 + 右上角常驻刷新按钮
|
||||
|
||||
Reference in New Issue
Block a user