1- import type { EditorId , EnvironmentId , ResolvedKeybindingsConfig } from "@t3tools/contracts" ;
1+ import {
2+ buildRemoteOpenUrl ,
3+ type EditorId ,
4+ type EnvironmentId ,
5+ type ResolvedKeybindingsConfig ,
6+ } from "@t3tools/contracts" ;
27import { useEffect } from "react" ;
38
49import { usePreferredEditor } from "../../editorPreferences" ;
510import { editorLabelForPlatform } from "../../editorLabels" ;
611import { isOpenFavoriteEditorShortcut } from "../../keybindings" ;
712import { announce } from "../../lib/announce" ;
8- import { useRemoteOpenState } from "../../remoteOpen" ;
13+ import { openRemoteEditorUrl , useRemoteCapableEditors , useRemoteOpenState } from "../../remoteOpen" ;
914import { registerCommands } from "../../shortcuts/dispatcher" ;
1015import { shellEnvironment } from "../../state/shell" ;
1116import { useAtomCommand } from "../../state/use-atom-command" ;
@@ -49,18 +54,39 @@ export function useOpenFavoriteEditorShortcut({
4954 openInCwd : string | null ;
5055} ) {
5156 const openInEditorMutation = useAtomCommand ( shellEnvironment . openInEditor , "open in editor" ) ;
52- const [ preferredEditor ] = usePreferredEditor ( availableEditors ) ;
5357 const remote = useRemoteOpenState ( environmentId ) ;
58+ const remoteCapableEditors = useRemoteCapableEditors ( ) ;
59+ // Matches the picker: remote editors run on the viewing machine.
60+ const [ preferredEditor ] = usePreferredEditor (
61+ remote . mode === "local-exec" ? availableEditors : remoteCapableEditors ,
62+ ) ;
5463
55- // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes a window keydown listener for the open-in-editor shortcut while enabled locally
64+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes a window keydown listener for the open-in-editor shortcut while enabled
5665 useEffect ( ( ) => {
57- if ( ! enabled || remote . mode !== "local-exec ") return ;
66+ if ( ! enabled || remote . mode === "remote-unavailable ") return ;
5867 const handler = ( event : globalThis . KeyboardEvent ) => {
59- if ( event . defaultPrevented || ! isOpenFavoriteEditorShortcut ( event , keybindings ) ) return ;
68+ if (
69+ event . repeat ||
70+ event . defaultPrevented ||
71+ ! isOpenFavoriteEditorShortcut ( event , keybindings )
72+ )
73+ return ;
6074 if ( ! openInCwd || ! preferredEditor ) return ;
6175
6276 event . preventDefault ( ) ;
6377 const label = editorLabelForPlatform ( preferredEditor , navigator . platform ) ;
78+ if ( remote . mode === "remote-links" ) {
79+ const url = buildRemoteOpenUrl ( {
80+ editor : preferredEditor ,
81+ ...remote . host ,
82+ absolutePath : openInCwd ,
83+ } ) ;
84+ if ( url === undefined ) return ;
85+ void openRemoteEditorUrl ( url ) . then ( ( opened ) => {
86+ if ( opened ) announce ( `Opened in ${ label } ` ) ;
87+ } ) ;
88+ return ;
89+ }
6490 void openInEditorMutation ( {
6591 environmentId,
6692 input : {
@@ -80,6 +106,6 @@ export function useOpenFavoriteEditorShortcut({
80106 openInCwd ,
81107 openInEditorMutation ,
82108 preferredEditor ,
83- remote . mode ,
109+ remote ,
84110 ] ) ;
85111}
0 commit comments