@@ -404,17 +404,10 @@ impl ConventionalCommitPopup {
404
404
}
405
405
406
406
#[ inline]
407
- fn draw_matches_list ( & self , f : & mut Frame , mut area : Rect ) {
408
- // Block has two lines up and down which need to be considered
409
- const HEIGHT_BLOCK_MARGIN : usize = 2 ;
410
-
407
+ fn draw_matches_list ( & self , f : & mut Frame , area : Rect ) {
411
408
let height = usize:: from ( area. height ) ;
412
409
let width = usize:: from ( area. width ) ;
413
410
414
- let list_height = height. saturating_sub ( HEIGHT_BLOCK_MARGIN ) ;
415
-
416
- let scroll_skip =
417
- self . selected_index . saturating_sub ( list_height) ;
418
411
let quick_shortcuts = self . quick_shortcuts ( ) ;
419
412
420
413
let title = format ! (
@@ -426,19 +419,19 @@ impl ConventionalCommitPopup {
426
419
}
427
420
) ;
428
421
429
- let iter_over = if let Some ( commit_type) =
430
- & self . seleted_commit_type
431
- {
422
+ let iter_over = if self . seleted_commit_type . is_some ( ) {
432
423
self . query_results_more_info
433
424
. iter ( )
434
425
. enumerate ( )
435
426
. take ( height)
436
427
. map ( |( idx, more_info) | {
437
428
let ( emoji, _, long_name) = more_info. strings ( ) ;
438
429
let text_string = format ! ( "{emoji} {long_name}" ) ;
439
- let text =
440
- trim_length_left ( & text_string, width - 4 ) ;
441
- ( self . selected_index == idx, text. to_owned ( ) )
430
+ let text = trim_length_left ( & text_string, width) ;
431
+ (
432
+ self . selected_index == idx,
433
+ format ! ( "{text}{:width$}" , " " ) ,
434
+ )
442
435
} )
443
436
. collect_vec ( )
444
437
} else {
@@ -453,20 +446,17 @@ impl ConventionalCommitPopup {
453
446
. enumerate ( )
454
447
. take ( height)
455
448
. map ( |( idx, commit_type) | {
456
- let commit_type_string = commit_type. to_string ( ) ;
457
- let text = trim_length_left (
458
- commit_type_string. as_str ( ) ,
459
- width - 4 , // ` [k]`
449
+ let text_string = format ! (
450
+ "{:w$} [{}]" ,
451
+ commit_type,
452
+ quick_shortcuts[ idx] ,
453
+ w = max_len. unwrap_or_default( ) ,
460
454
) ;
455
+ let text = trim_length_left ( & text_string, width) ;
461
456
462
457
(
463
458
self . selected_index == idx,
464
- format ! (
465
- "{:w$} [{}]" ,
466
- text,
467
- quick_shortcuts[ idx] ,
468
- w = max_len. unwrap_or_default( ) ,
469
- ) ,
459
+ format ! ( "{text}{:width$}" , " " ) ,
470
460
)
471
461
} )
472
462
. collect_vec ( )
@@ -580,6 +570,15 @@ impl ConventionalCommitPopup {
580
570
} )
581
571
. cloned ( )
582
572
. collect_vec ( ) ;
573
+
574
+ if self . selected_index
575
+ >= self . query_results_more_info . len ( )
576
+ {
577
+ self . selected_index = self
578
+ . query_results_more_info
579
+ . len ( )
580
+ . saturating_sub ( 1 ) ;
581
+ }
583
582
} else {
584
583
self . query_results_type = self
585
584
. options
@@ -589,6 +588,11 @@ impl ConventionalCommitPopup {
589
588
} )
590
589
. cloned ( )
591
590
. collect_vec ( ) ;
591
+
592
+ if self . selected_index >= self . query_results_type . len ( ) {
593
+ self . selected_index =
594
+ self . query_results_type . len ( ) . saturating_sub ( 1 ) ;
595
+ }
592
596
}
593
597
}
594
598
0 commit comments