@@ -43,31 +43,49 @@ fn open_in_external_editor_impl(path: &str, editor: &str) -> Result<()> {
4343 }
4444 } ;
4545
46- let status = command. status ( ) . map_err ( |e| AppError :: Io ( e) ) ?;
47- if !status. success ( ) {
48- // If failed, try using 'open -a' as a fallback for Mac
49- let app_name = match editor {
50- "code" => Some ( "Visual Studio Code" ) ,
51- "cursor" => Some ( "Cursor" ) ,
52- "idea" => Some ( "IntelliJ IDEA" ) ,
53- "webstorm" => Some ( "WebStorm" ) ,
54- "sublime" => Some ( "Sublime Text" ) ,
55- _ => None ,
46+ // Try to run the command directly
47+ let status_result = command. status ( ) ;
48+
49+ // Check if command failed to start (IO error) or returned non-success status
50+ let should_try_fallback = match status_result {
51+ Ok ( status) => !status. success ( ) ,
52+ Err ( _) => true ,
53+ } ;
54+
55+ if should_try_fallback {
56+ let mut fallback_apps = Vec :: new ( ) ;
57+
58+ match editor {
59+ "code" => {
60+ fallback_apps. push ( "Visual Studio Code" ) ;
61+ fallback_apps. push ( "Visual Studio Code - Insiders" ) ;
62+ fallback_apps. push ( "Cursor" ) ;
63+ } ,
64+ "cursor" => fallback_apps. push ( "Cursor" ) ,
65+ "idea" => fallback_apps. push ( "IntelliJ IDEA" ) ,
66+ "webstorm" => fallback_apps. push ( "WebStorm" ) ,
67+ "sublime" => fallback_apps. push ( "Sublime Text" ) ,
68+ _ => { } ,
5669 } ;
5770
58- if let Some ( app) = app_name {
59- let status = Command :: new ( "open" )
71+ let mut success = false ;
72+ for app in fallback_apps {
73+ let status = Command :: new ( "open" )
6074 . arg ( "-a" )
6175 . arg ( app)
6276 . arg ( path)
63- . status ( )
64- . map_err ( |e| AppError :: Io ( e) ) ?;
77+ . status ( ) ;
6578
66- if !status. success ( ) {
67- return Err ( AppError :: InvalidInput ( format ! ( "Failed to open editor: {}" , editor) ) ) ;
79+ if let Ok ( s) = status {
80+ if s. success ( ) {
81+ success = true ;
82+ break ;
83+ }
6884 }
69- } else {
70- return Err ( AppError :: InvalidInput ( format ! ( "Failed to open editor: {}" , editor) ) ) ;
85+ }
86+
87+ if !success {
88+ return Err ( AppError :: InvalidInput ( format ! ( "Failed to open editor: {}. Please check if the editor is installed." , editor) ) ) ;
7189 }
7290 }
7391 }
0 commit comments