Skip to content

Commit 4d0cf66

Browse files
authored
fix(preview): activate selected files by keyboard (#152)
## What changed - select the requested Files explorer entry through the existing bounded bridge - activate it with the explorer's supported Space keyboard action - keep acknowledgement gated on the requested editor tab actually opening ## Why The code-server explorer accepts programmatic selection but does not open files from synthetic double-click events. Its keyboard activation path opens image and document editors reliably. ## Verification - `pnpm turbo typecheck lint build` - reproduced the Space activation against the production code-server sandbox before implementing the bridge change - final end-to-end production verification will run after deployment
1 parent 7b4df6b commit 4d0cf66

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

packages/preview-bridge/src/index.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,19 @@ target.dispatchEvent(new MouseEvent(mouseEvents[j],{bubbles:true,cancelable:true
140140
}
141141
}
142142
143-
function dispatchDoubleClick(target){
144-
if(!target)return;
145-
dispatchClick(target,1);
143+
function activateTreeItem(row){
144+
if(!row)return;
145+
var target=row.querySelector(".label-name,.monaco-icon-label,.monaco-tl-contents")||row;
146+
dispatchClick(target);
146147
setTimeout(function(){
147-
dispatchClick(target,2);
148-
target.dispatchEvent(new MouseEvent("dblclick",{bubbles:true,cancelable:true,button:0,buttons:0,detail:2,view:window}));
149-
},120);
148+
var tree=row.closest("[role='tree']");
149+
if(!tree)return;
150+
if(typeof tree.focus==="function")tree.focus();
151+
var options={bubbles:true,cancelable:true,composed:true,key:" ",code:"Space",keyCode:32,charCode:32,which:32};
152+
tree.dispatchEvent(new KeyboardEvent("keydown",options));
153+
tree.dispatchEvent(new KeyboardEvent("keypress",options));
154+
tree.dispatchEvent(new KeyboardEvent("keyup",options));
155+
},50);
150156
}
151157
152158
function visible(el){
@@ -234,8 +240,7 @@ var isRequestedFile=cheatcodeInitialFileName&&text.indexOf(cheatcodeInitialFileN
234240
var isDeliverable=/\.(pptx?|pdf|docx?|xlsx?|ods|odt)\b/i.test(text);
235241
if((isRequestedFile||(!cheatcodeInitialFileName&&isDeliverable))&&visible(rows[i])){
236242
window.__CHEATCODE_CS_OPENED_INITIAL_DELIVERABLE__=true;
237-
var target=rows[i].querySelector(".label-name,.monaco-icon-label,.monaco-tl-contents")||rows[i];
238-
dispatchDoubleClick(target);
243+
activateTreeItem(rows[i]);
239244
break;
240245
}
241246
}
@@ -309,8 +314,7 @@ dispatchClick(twistie);
309314
setTimeout(function(){openRequestedFileStep(parts,index+1,level===null?null:level+1,requestId,attempt+1)},120);
310315
return;
311316
}
312-
var target=row.querySelector(".label-name,.monaco-icon-label,.monaco-tl-contents")||row;
313-
dispatchDoubleClick(target);
317+
activateTreeItem(row);
314318
setTimeout(function(){confirmRequestedFileOpen(parts[index],requestId,0)},200);
315319
}
316320

0 commit comments

Comments
 (0)