1
+ use std:: vec;
2
+
1
3
use anyhow:: Result ;
2
4
use tracing:: instrument;
3
5
@@ -11,7 +13,7 @@ use crate::{
11
13
env:: { Config , DiffFormat } ,
12
14
ui:: {
13
15
Component , ComponentAction , details_panel:: DetailsPanel , help_popup:: HelpPopup ,
14
- utils:: tabs_to_spaces,
16
+ message_popup :: MessagePopup , utils:: tabs_to_spaces,
15
17
} ,
16
18
} ;
17
19
@@ -143,6 +145,14 @@ impl FilesTab {
143
145
Ok ( ( ) )
144
146
}
145
147
148
+ pub fn untrack_file ( & mut self , commander : & mut Commander ) -> Result < ( ) > {
149
+ self . file
150
+ . as_ref ( )
151
+ . map ( |current_file| commander. untrack_file ( current_file) )
152
+ . transpose ( ) ?;
153
+ Ok ( ( ) )
154
+ }
155
+
146
156
fn scroll_files ( & mut self , commander : & mut Commander , scroll : isize ) -> Result < ( ) > {
147
157
if let Ok ( files) = self . files_output . as_ref ( ) {
148
158
let current_file_index = self . get_current_file_index ( ) ;
@@ -318,6 +328,19 @@ impl Component for FilesTab {
318
328
self . diff_format = self . diff_format . get_next ( self . config . diff_tool ( ) ) ;
319
329
self . refresh_diff ( commander) ?;
320
330
}
331
+ KeyCode :: Char ( 'x' ) => {
332
+ // this works even for deleted files because jj doesn't return error in that case
333
+ if self . untrack_file ( commander) . is_err ( ) {
334
+ return Ok ( ComponentInputResult :: HandledAction (
335
+ ComponentAction :: SetPopup ( Some ( Box :: new ( MessagePopup {
336
+ title : "Can't untrack file" . into ( ) ,
337
+ messages : "Make sure that file is ignored" . into ( ) ,
338
+ text_align : None ,
339
+ } ) ) ) ,
340
+ ) ) ;
341
+ }
342
+ self . set_head ( commander, & commander. get_current_head ( ) ?) ?;
343
+ }
321
344
KeyCode :: Char ( 'R' ) | KeyCode :: F ( 5 ) => {
322
345
self . head = commander. get_head_latest ( & self . head ) ?;
323
346
self . refresh_files ( commander) ?;
@@ -333,6 +356,7 @@ impl Component for FilesTab {
333
356
vec ! [
334
357
( "j/k" . to_owned( ) , "scroll down/up" . to_owned( ) ) ,
335
358
( "J/K" . to_owned( ) , "scroll down by ½ page" . to_owned( ) ) ,
359
+ ( "x" . to_owned( ) , "untrack file" . to_owned( ) ) ,
336
360
( "@" . to_owned( ) , "view current change files" . to_owned( ) ) ,
337
361
] ,
338
362
vec ! [
0 commit comments