diff --git a/docs/assets/qa/command-search/search-after.png b/docs/assets/qa/command-search/search-after.png new file mode 100644 index 000000000..063157aa1 Binary files /dev/null and b/docs/assets/qa/command-search/search-after.png differ diff --git a/docs/assets/qa/command-search/search-before.png b/docs/assets/qa/command-search/search-before.png new file mode 100644 index 000000000..0247f1103 Binary files /dev/null and b/docs/assets/qa/command-search/search-before.png differ diff --git a/e2e/ui/05-command-search.spec.mjs b/e2e/ui/05-command-search.spec.mjs new file mode 100644 index 000000000..369555fcf --- /dev/null +++ b/e2e/ui/05-command-search.spec.mjs @@ -0,0 +1,38 @@ +import {test,expect} from './fixtures.mjs'; +import {post,del,track,cleanup} from '../lib/api.mjs'; +import {cfg} from '../lib/env.mjs'; + +test.afterEach(cleanup); + +test('command search follows visible English labels, issue numbers and keyboard focus', async ({page})=>{ + await page.addInitScript(()=>localStorage.setItem('loopforge.lang','en')); + const title=`Palette ${cfg.runTag}`; + const issue=await post('/api/issues',{projectId:cfg.projectId,title,description:'Command search acceptance',sopMode:'none'}); + track(`palette issue ${issue.id}`,()=>del(`/api/issues/${encodeURIComponent(issue.id)}`)); + await page.goto('/#/issues'); + const opener=page.locator('#commandPaletteTrigger'); + const search=page.locator('#commandSearch'); + const close=page.locator('#commandClose'); + const label=await page.locator('#pageTitle').innerText(); + const row=page.locator(`.issue-table-row[data-id="${issue.id}"]`); + await expect(row).toBeVisible(); + const key=await row.locator('.issue-key-cell').getAttribute('title'); + await opener.click(); + await search.fill(label); + await expect(page.getByRole('option').filter({hasText:label}).first()).toBeVisible(); + await search.fill(key); + await expect(page.getByRole('option').first()).toContainText(key); + await search.fill('no matching search command'); + await expect(page.locator('#commandEmpty')).toBeVisible(); + await page.keyboard.press('Tab'); + await expect(close).toBeFocused(); + await page.keyboard.press('Shift+Tab'); + await expect(search).toBeFocused(); + await page.keyboard.press('Escape'); + await expect(opener).toBeFocused(); + await page.keyboard.press('Control+k'); + await search.press('ArrowDown'); + await expect(search).toHaveAttribute('aria-activedescendant','command-result-1'); + await search.press('Enter'); + await expect(page).toHaveURL(/#\/collaboration$/); +}); diff --git a/web/app.js b/web/app.js index e8998bc84..b16a66206 100644 --- a/web/app.js +++ b/web/app.js @@ -1080,6 +1080,9 @@ function bind(){ }); } $('#commandPaletteTrigger').onclick=openCommandPalette; + $('#commandClose').onclick=closeCommandPalette; + const commandShortcut=/Mac|iPhone|iPad|iPod/i.test(navigator.platform)?'⌘K':'Ctrl+K'; + $$('[data-command-shortcut]').forEach(el=>{el.textContent=commandShortcut}); $('#commandPalette').onclick=e=>{if(e.target===$('#commandPalette'))closeCommandPalette()}; $('#commandSearch').oninput=renderCommandResults; $('#commandResults').onclick=e=>{const item=e.target.closest('[data-command-index]');if(item)executeCommand(Number(item.dataset.commandIndex))}; @@ -1290,13 +1293,8 @@ function bind(){ modal.classList.remove('open'); })); document.addEventListener('keydown',e=>{ - if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==='k'){e.preventDefault();openCommandPalette();return} - if(!$('#commandPalette').hidden){ - if(e.key==='Escape'){closeCommandPalette();return} - if(e.key==='ArrowDown'){e.preventDefault();moveCommandSelection(1);return} - if(e.key==='ArrowUp'){e.preventDefault();moveCommandSelection(-1);return} - if(e.key==='Enter'){e.preventDefault();executeCommand(commandSelectedIndex);return} - } + if(!$('#commandPalette').hidden){handleCommandKeys(e);return} + if(!e.isComposing&&(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()==='k'){e.preventDefault();openCommandPalette();return} if(e.key==='Escape'){ if(flowDesignerEscape(e))return; if($('#artifactModal')?.classList.contains('open')){$('#artifactModal').classList.remove('open');return} diff --git a/web/app/access.js b/web/app/access.js index 15635d4c8..57953ef1d 100644 --- a/web/app/access.js +++ b/web/app/access.js @@ -145,35 +145,79 @@ async function revokePersonalToken(id){ } -let commandMatches=[],commandSelectedIndex=0; +let commandMatches=[],commandSelectedIndex=0,commandOpener=null; function commandCatalog(){ - const pages=[['collaboration','AI 工作台','和 AI 对话,派发与跟进任务'],['issues','需求列表','查看进度,触发或重试'],['approvals','待我确认','批准或退回卡住的需求'],['observability','统计','用量分析 · Token 与质量'],['settings','个人配置','账号、模型与执行凭据'],['projects','项目配置','项目、成员和仓库'],['bots','通道管理','企业微信单聊或群聊通知通道'],['sops','流程模板','Issue 修复与需求开发'],['runs','运行记录','查看节点日志和产物'],['aiSchedules','定时任务','提示词任务、SOP 触发与共享任务'],['agents','角色定义','管理角色和能力资产'],['mcp','能力资产 · MCP','添加项目级或个人 MCP'],['rules','能力资产 · 规则','当前项目的行为与执行约束'],['skills','能力资产 · 技能','当前项目的技能和附加文件'],['runners','执行机器','用自己的电脑或 CVM 跑任务'],['dockerfiles','环境资产 · Dockerfile','管理项目容器构建定义'],['environments','环境资产 · 安装脚本','管理隔离环境的工具安装脚本'],['sandboxes','环境资产 · 沙箱','管理项目运行隔离策略'],['guide','访问密钥','创建和撤销访问密钥']].map(([view,title,meta])=>({kind:'页面',title,meta,action:()=>switchView(view)})); - const issues=(state.data.issues||[]).map(i=>({kind:'需求',title:i.title,meta:`${i.priority||'—'} · ${issueStatusLabel(i.status)}`,action:()=>openIssueDetail(i.id)})); - const runs=sopRuns(state.data.runs).map(r=>({kind:'运行',title:runIssueTitle(r),meta:`${runDisplayStatus(r)} · ${r.workflowSnapshot?.name||r.workflowId}`,action:()=>openRunFromId(r.id)})); - const sops=catalogWorkflows().map(w=>({kind:'SOP',title:w.name,meta:`${w.status==='published'?'已发布':'草稿'} · ${w.nodes?.length||0} 个节点`,action:()=>{state.workflow=clone(w);state.selectedNode=null;switchView('flow')}})); - const agents=(state.data.agents||[]).map(a=>({kind:'Agent',title:a.name,meta:a.description||a.id,action:()=>{switchView('agents');openAgentWizard(a)}})); + const pages=[['collaboration','AI 工作台','和 AI 对话,派发与跟进任务'],['issues','需求列表','查看进度,触发或重试'],['assistant','AI 助手','自定义规则'],['flow','流程设计','SOP'],['approvals','待我确认','批准或退回卡住的需求'],['observability','统计','用量分析 · Token 与质量'],['settings','个人配置','账号、模型与执行凭据'],['projects','项目配置','项目、成员和仓库'],['bots','通道管理','企业微信单聊或群聊通知通道'],['sops','流程模板','Issue 修复与需求开发'],['runs','运行记录','查看节点日志和产物'],['aiSchedules','定时任务','提示词任务、SOP 触发与共享任务'],['agents','角色定义','管理角色和能力资产'],['mcp','能力资产 · MCP','添加项目级或个人 MCP'],['rules','能力资产 · 规则','当前项目的行为与执行约束'],['skills','能力资产 · 技能','当前项目的技能和附加文件'],['runners','执行机器','用自己的电脑或 CVM 跑任务'],['dockerfiles','环境资产 · Dockerfile','管理项目容器构建定义'],['environments','环境资产 · 安装脚本','管理隔离环境的工具安装脚本'],['sandboxes','环境资产 · 沙箱','管理项目运行隔离策略'],['guide','访问密钥','创建和撤销访问密钥'],...(isPlatformAdmin()?[['platform','平台管理','平台管理员']]:[])].map(([view,title,meta])=>({kind:'页面',title,meta,action:()=>switchView(view)})); + const issues=(state.data.issues||[]).map(i=>({kind:'需求',id:[i.id,i.externalRef?.externalId,i.externalRef?.externalIid&&`#${i.externalRef.externalIid}`].filter(Boolean).join(' '),title:i.title,meta:`${issueKeyLabel(i)} · ${i.priority||'—'} · ${issueStatusLabel(i.status)}`,action:()=>openIssueDetail(i.id)})); + const runs=sopRuns(state.data.runs).map(r=>({kind:'运行',id:r.id,title:runIssueTitle(r),meta:`${runDisplayStatus(r)} · ${r.workflowSnapshot?.name||r.workflowId}`,action:()=>openRunFromId(r.id)})); + const sops=catalogWorkflows().map(w=>({kind:'SOP',id:w.id,title:w.name,meta:`${w.status==='published'?'已发布':'草稿'} · ${w.nodes?.length||0} 个节点`,action:()=>openSOPDesigner(w.id)})); + const agents=(state.data.agents||[]).map(a=>({kind:'Agent',id:a.id,title:a.name,meta:a.description||a.id,action:()=>{switchView('agents');openAgentWizard(a)}})); const actions=[{kind:'操作',title:'新建 SOP',meta:'创建流程草稿',action:openSOPWizard}]; return [...actions,...pages,...issues,...runs,...sops,...agents]; } -function openCommandPalette(){const host=$('#commandPalette');host.hidden=false;$('#commandSearch').value='';renderCommandResults();requestAnimationFrame(()=>$('#commandSearch').focus())} -function closeCommandPalette(){$('#commandPalette').hidden=true} +function openCommandPalette(){ + const host=$('#commandPalette'), search=$('#commandSearch'); + if(!host.hidden){search.focus();return} + commandOpener=document.activeElement===document.body?$('#commandPaletteTrigger'):document.activeElement; + host.hidden=false; + search.value=''; + renderCommandResults(); + search.focus(); +} +function closeCommandPalette(){ + $('#commandPalette').hidden=true; + if(commandOpener?.isConnected)commandOpener.focus({preventScroll:true}); + commandOpener=null; +} function moveCommandSelection(delta){ if(!commandMatches.length)return; commandSelectedIndex=(commandSelectedIndex+delta+commandMatches.length)%commandMatches.length; highlightCommandSelection(); } function highlightCommandSelection(){ + const search=$('#commandSearch'); + search.removeAttribute('aria-activedescendant'); $$('#commandResults [data-command-index]').forEach((el,i)=>{ - el.classList.toggle('selected',i===commandSelectedIndex); - if(i===commandSelectedIndex)el.scrollIntoView({block:'nearest'}); + const selected=i===commandSelectedIndex; + el.classList.toggle('selected',selected); + el.setAttribute('aria-selected',String(selected)); + if(selected){search.setAttribute('aria-activedescendant',el.id);el.scrollIntoView({block:'nearest'})} }); } function renderCommandResults(){ - const q=$('#commandSearch').value.trim().toLowerCase(); - commandMatches=commandCatalog().filter(x=>!q||`${x.kind} ${x.title} ${x.meta}`.toLowerCase().includes(q)).slice(0,12); + const query=$('#commandSearch').value.trim().toLowerCase(); + const translate=window.lfTranslate||((value)=>value); + commandMatches=commandCatalog().filter(item=>{ + if(!query)return true; + const terms=[item.kind,translate(item.kind),item.title,item.meta,item.id]; + if(item.kind==='页面'||item.kind==='操作')terms.push(translate(item.title),translate(item.meta)); + return terms.join(' ').toLowerCase().includes(query); + }).slice(0,12); commandSelectedIndex=0; - $('#commandResults').innerHTML=commandMatches.length - ?commandMatches.map((x,i)=>``).join('') - :`