@@ -2,7 +2,7 @@ use super::{CommandBlocking, DrawableComponent, ScrollType};
22use crate :: {
33 components:: { CommandInfo , Component } ,
44 keys,
5- queue:: { InternalEvent , Queue } ,
5+ queue:: { Action , InternalEvent , Queue } ,
66 strings,
77 ui:: { calc_scroll_top, style:: Theme } ,
88} ;
@@ -284,9 +284,32 @@ impl DiffComponent {
284284 Ok ( ( ) )
285285 }
286286
287+ fn reset_hunk ( & self ) -> Result < ( ) > {
288+ if let Some ( hunk) = self . selected_hunk {
289+ let hash = self . diff . hunks [ hunk] . header_hash ;
290+
291+ self . queue
292+ . as_ref ( )
293+ . expect ( "try using queue in immutable diff" )
294+ . borrow_mut ( )
295+ . push_back ( InternalEvent :: ConfirmAction (
296+ Action :: ResetHunk (
297+ self . current . path . clone ( ) ,
298+ hash,
299+ ) ,
300+ ) ) ;
301+ }
302+
303+ Ok ( ( ) )
304+ }
305+
287306 fn is_immutable ( & self ) -> bool {
288307 self . queue . is_none ( )
289308 }
309+
310+ const fn is_stage ( & self ) -> bool {
311+ self . current . is_stage
312+ }
290313}
291314
292315impl DrawableComponent for DiffComponent {
@@ -350,12 +373,17 @@ impl Component for DiffComponent {
350373 out. push ( CommandInfo :: new (
351374 commands:: DIFF_HUNK_REMOVE ,
352375 self . selected_hunk . is_some ( ) ,
353- self . focused && self . current . is_stage ,
376+ self . focused && self . is_stage ( ) ,
354377 ) ) ;
355378 out. push ( CommandInfo :: new (
356379 commands:: DIFF_HUNK_ADD ,
357380 self . selected_hunk . is_some ( ) ,
358- self . focused && !self . current . is_stage ,
381+ self . focused && !self . is_stage ( ) ,
382+ ) ) ;
383+ out. push ( CommandInfo :: new (
384+ commands:: DIFF_HUNK_REVERT ,
385+ self . selected_hunk . is_some ( ) ,
386+ self . focused && !self . is_stage ( ) ,
359387 ) ) ;
360388 }
361389
@@ -394,6 +422,13 @@ impl Component for DiffComponent {
394422 self . add_hunk ( ) ?;
395423 Ok ( true )
396424 }
425+ keys:: DIFF_RESET_HUNK
426+ if !self . is_immutable ( )
427+ && !self . is_stage ( ) =>
428+ {
429+ self . reset_hunk ( ) ?;
430+ Ok ( true )
431+ }
397432 _ => Ok ( false ) ,
398433 } ;
399434 }
0 commit comments