@@ -6,9 +6,10 @@ import {
66 type EnvironmentId ,
77 type ResolvedKeybindingsConfig ,
88} from "@t3tools/contracts" ;
9- import { memo , use , useEffect , useRef } from "react" ;
9+ import { memo , use , useRef } from "react" ;
1010import { BackgroundThreadContext } from "./backgroundThread" ;
11- import { isOpenFavoriteEditorShortcut , shortcutLabelForCommand } from "../../keybindings" ;
11+ import { shortcutLabelForCommand } from "../../keybindings" ;
12+ import { OPEN_FAVORITE_EDITOR_ATTRIBUTE } from "./OpenInPickerShortcut" ;
1213import { usePreferredEditor } from "../../editorPreferences" ;
1314import { editorLabelForPlatform } from "../../editorLabels" ;
1415import {
@@ -281,38 +282,6 @@ export const OpenInPicker = memo(function OpenInPicker({
281282 ) ;
282283
283284 const backgroundThread = use ( BackgroundThreadContext ) ;
284- useEffect ( ( ) => {
285- if ( ! enableShortcut || ! canOpenEditor || backgroundThread ) return ;
286- const handler = ( e : globalThis . KeyboardEvent ) => {
287- if ( e . defaultPrevented || ! isOpenFavoriteEditorShortcut ( e , keybindings ) ) return ;
288- if ( ! openInCwd ) return ;
289- if ( ! preferredEditor ) return ;
290- if (
291- remote . mode === "local-exec" &&
292- ! readEnvironmentScope ( environmentId , AuthOrchestrationOperateScope )
293- )
294- return ;
295-
296- e . preventDefault ( ) ;
297- const label = editorLabelForPlatform ( preferredEditor , navigator . platform ) ;
298- void openInEditor ( preferredEditor ) . then ( ( opened ) => {
299- if ( opened ) announce ( `Opened in ${ label } ` ) ;
300- } ) ;
301- } ;
302- window . addEventListener ( "keydown" , handler , true ) ;
303- return ( ) => window . removeEventListener ( "keydown" , handler , true ) ;
304- } , [
305- backgroundThread ,
306- canOpenEditor ,
307- enableShortcut ,
308- environmentId ,
309- keybindings ,
310- openInCwd ,
311- openInEditor ,
312- preferredEditor ,
313- remote . mode ,
314- ] ) ;
315- // Derive after the shortcut effect to preserve the editor list's compiler cache.
316285 const options = resolveOpenInOptions ( navigator . platform , effectiveEditors ) ;
317286 const primaryOption = options . find ( ( { value } ) => value === preferredEditor ) ?? null ;
318287 const primaryLabel = isPanel ? `Open in ${ primaryOption ?. label ?? "editor" } ` : "Open" ;
@@ -402,7 +371,14 @@ export const OpenInPicker = memo(function OpenInPicker({
402371 part = "primary"
403372 panel = { isPanel }
404373 disabled = { ! preferredEditor || ! openInCwd || ! canOpenEditor }
405- onClick = { ( ) => openInEditor ( preferredEditor ) }
374+ { ...( enableShortcut && ! backgroundThread ? { [ OPEN_FAVORITE_EDITOR_ATTRIBUTE ] : "" } : { } ) }
375+ onClick = { ( ) => {
376+ if ( ! preferredEditor ) return ;
377+ const label = editorLabelForPlatform ( preferredEditor , navigator . platform ) ;
378+ void openInEditor ( preferredEditor ) . then ( ( opened ) => {
379+ if ( opened ) announce ( `Opened in ${ label } ` ) ;
380+ } ) ;
381+ } }
406382 >
407383 { primaryOption ?. Icon ? (
408384 < primaryOption . Icon
0 commit comments