@@ -5,8 +5,7 @@ use super::{
5
5
use crate :: {
6
6
get_app_config_path, keys,
7
7
queue:: { InternalEvent , NeedsUpdate , Queue } ,
8
- strings,
9
- strings:: { commands, COMMIT_EDITOR_MSG } ,
8
+ strings:: { self , commands} ,
10
9
ui:: style:: SharedTheme ,
11
10
} ;
12
11
use anyhow:: { anyhow, Result } ;
@@ -67,6 +66,12 @@ impl Component for CommitComponent {
67
66
self . can_amend ( ) ,
68
67
true ,
69
68
) ) ;
69
+
70
+ out. push ( CommandInfo :: new (
71
+ commands:: COMMIT_OPEN_EDITOR ,
72
+ true ,
73
+ true ,
74
+ ) ) ;
70
75
}
71
76
72
77
visibility_blocking ( self )
@@ -88,6 +93,12 @@ impl Component for CommitComponent {
88
93
self . amend ( ) ?;
89
94
}
90
95
96
+ keys:: OPEN_COMMIT_EDITOR => {
97
+ self . queue
98
+ . borrow_mut ( )
99
+ . push_back ( InternalEvent :: SuspendPolling ) ;
100
+ }
101
+
91
102
_ => ( ) ,
92
103
} ;
93
104
@@ -137,9 +148,15 @@ impl CommitComponent {
137
148
let mut config_path: PathBuf = get_app_config_path ( ) ?;
138
149
config_path. push ( COMMIT_MSG_FILE_NAME ) ;
139
150
140
- let mut file = File :: create ( & config_path) ?;
141
- file. write_all ( COMMIT_EDITOR_MSG . as_bytes ( ) ) ?;
142
- drop ( file) ;
151
+ {
152
+ //TODO: use a tmpfile here
153
+ let mut file = File :: create ( & config_path) ?;
154
+ file. write_fmt ( format_args ! (
155
+ "{}\n " ,
156
+ self . input. get_text( )
157
+ ) ) ?;
158
+ file. write_all ( strings:: COMMIT_EDITOR_MSG . as_bytes ( ) ) ?;
159
+ }
143
160
144
161
let mut editor = env:: var ( "GIT_EDTIOR" )
145
162
. ok ( )
@@ -156,9 +173,8 @@ impl CommitComponent {
156
173
} ) ?;
157
174
158
175
io:: stdout ( ) . execute ( LeaveAlternateScreen ) ?;
159
-
160
176
defer ! {
161
- io:: stdout( ) . execute( EnterAlternateScreen ) . expect( "failed to reset terminal" ) ;
177
+ io:: stdout( ) . execute( EnterAlternateScreen ) . expect( "reset terminal" ) ;
162
178
}
163
179
164
180
Command :: new ( command)
@@ -168,6 +184,7 @@ impl CommitComponent {
168
184
169
185
let mut message = String :: new ( ) ;
170
186
187
+ //TODO: see above
171
188
let mut file = File :: open ( & config_path) ?;
172
189
file. read_to_string ( & mut message) ?;
173
190
drop ( file) ;
@@ -184,9 +201,9 @@ impl CommitComponent {
184
201
} )
185
202
. collect ( ) ;
186
203
187
- if ! message. chars ( ) . all ( char :: is_whitespace ) {
188
- return self . commit_msg ( message ) ;
189
- }
204
+ let message = message . trim ( ) . to_string ( ) ;
205
+
206
+ self . input . set_text ( message ) ;
190
207
191
208
Ok ( ( ) )
192
209
}
0 commit comments