@@ -58,49 +58,45 @@ impl Editor {
5858 }
5959
6060 pub fn open (
61- self ,
61+ mut self ,
6262 exercise_ind : usize ,
6363 exercise_path : & ' static str ,
6464 ) -> Result < EditorJoinHandle > {
6565 let handle = thread:: Builder :: new ( )
66- . spawn ( move || match self {
67- Editor :: VSCode => {
68- run_cmd ( Command :: new ( "code" ) . arg ( exercise_path) ) ?;
69-
70- Ok ( Self :: VSCode )
71- }
72- Editor :: Cmd ( program, args) => {
73- run_cmd ( Command :: new ( & program) . args ( & args) . arg ( exercise_path) ) ?;
74-
75- Ok ( Self :: Cmd ( program, args) )
76- }
77- Editor :: Zellij ( open_pane) => {
78- if let Some ( ( pane_id_str, pane_id, open_exercise_ind) ) = open_pane {
79- if open_exercise_ind == exercise_ind {
80- if zellij:: pane_open ( pane_id) ? {
81- return Ok ( Self :: Zellij ( Some ( (
82- pane_id_str,
83- pane_id,
84- exercise_ind,
85- ) ) ) ) ;
66+ . spawn ( move || {
67+ match & mut self {
68+ Editor :: VSCode => {
69+ run_cmd ( Command :: new ( "code" ) . arg ( exercise_path) ) ?;
70+ }
71+ Editor :: Cmd ( program, args) => {
72+ run_cmd ( Command :: new ( program) . args ( args) . arg ( exercise_path) ) ?;
73+ }
74+ Editor :: Zellij ( open_pane) => {
75+ if let Some ( ( pane_id_str, pane_id, open_exercise_ind) ) = open_pane {
76+ if * open_exercise_ind == exercise_ind {
77+ if zellij:: pane_open ( * pane_id) ? {
78+ return Ok ( self ) ;
79+ }
80+ } else {
81+ zellij:: close_pane ( pane_id_str) ?;
8682 }
87- } else {
88- zellij:: close_pane ( & pane_id_str) ?;
8983 }
90- }
9184
92- let stdout = run_cmd (
93- Command :: new ( "zellij" )
94- . arg ( "action" )
95- . arg ( "edit" )
96- . arg ( exercise_path) ,
97- ) ?;
85+ let stdout = run_cmd (
86+ Command :: new ( "zellij" )
87+ . arg ( "action" )
88+ . arg ( "edit" )
89+ . arg ( exercise_path) ,
90+ ) ?;
9891
99- let ( pane_id_str, pane_id) = zellij:: parse_pane_id ( & stdout)
100- . context ( "Failed to parse the ID of the new Zellij pane" ) ?;
92+ let ( pane_id_str, pane_id) = zellij:: parse_pane_id ( & stdout)
93+ . context ( "Failed to parse the ID of the new Zellij pane" ) ?;
10194
102- Ok ( Self :: Zellij ( Some ( ( pane_id_str, pane_id, exercise_ind) ) ) )
95+ * open_pane = Some ( ( pane_id_str, pane_id, exercise_ind) ) ;
96+ }
10397 }
98+
99+ Ok ( self )
104100 } )
105101 . context ( "Failed to spawn a thread to open the editor" ) ?;
106102
0 commit comments