@@ -219,7 +219,7 @@ impl Component for BranchListPopup {
219
219
strings:: commands:: sort_branch ( & self . key_config ) ,
220
220
true ,
221
221
true ,
222
- ) )
222
+ ) ) ;
223
223
}
224
224
visibility_blocking ( self )
225
225
}
@@ -315,7 +315,7 @@ impl Component for BranchListPopup {
315
315
) ) ;
316
316
} else if key_match ( e, self . key_config . keys . branch_sort ) {
317
317
self . queue . push ( InternalEvent :: OpenBranchSortPopup (
318
- self . sort_by . clone ( ) ,
318
+ self . sort_by ,
319
319
) ) ;
320
320
}
321
321
}
@@ -480,10 +480,10 @@ impl BranchListPopup {
480
480
} ) ;
481
481
}
482
482
BranchListSortBy :: BranchNameAsc => {
483
- self . branches . sort_by ( |a, b| a. name . cmp ( & b. name ) )
483
+ self . branches . sort_by ( |a, b| a. name . cmp ( & b. name ) ) ;
484
484
}
485
485
BranchListSortBy :: BranchNameDesc => {
486
- self . branches . sort_by ( |a, b| b. name . cmp ( & a. name ) )
486
+ self . branches . sort_by ( |a, b| b. name . cmp ( & a. name ) ) ;
487
487
}
488
488
}
489
489
//remove remote branch called `HEAD`
@@ -635,6 +635,46 @@ impl BranchListPopup {
635
635
Ok ( ( ) )
636
636
}
637
637
638
+ const fn calculate_shared_commit_message_length (
639
+ width_available : u16 ,
640
+ three_dots_length : usize ,
641
+ ) -> usize {
642
+ const COMMIT_HASH_LENGTH : usize = 8 ;
643
+ const COMMIT_DATE_LENGTH : usize = 11 ;
644
+ const IS_HEAD_STAR_LENGTH : usize = 3 ;
645
+ let branch_name_length: usize =
646
+ width_available as usize * 40 / 100 ;
647
+
648
+ ( width_available as usize )
649
+ . saturating_sub ( COMMIT_HASH_LENGTH )
650
+ . saturating_sub ( COMMIT_DATE_LENGTH )
651
+ . saturating_sub ( branch_name_length)
652
+ . saturating_sub ( IS_HEAD_STAR_LENGTH )
653
+ . saturating_sub ( three_dots_length)
654
+ }
655
+
656
+ fn get_branch_name_text (
657
+ branch_name_length : usize ,
658
+ displaybranch : & BranchInfo ,
659
+ three_dots_length : usize ,
660
+ three_dots : & str ,
661
+ ) -> String {
662
+ let mut branch_name = displaybranch. name . clone ( ) ;
663
+ if branch_name. len ( )
664
+ > branch_name_length. saturating_sub ( three_dots_length)
665
+ {
666
+ branch_name = branch_name
667
+ . unicode_truncate (
668
+ branch_name_length
669
+ . saturating_sub ( three_dots_length) ,
670
+ )
671
+ . 0
672
+ . to_string ( ) ;
673
+ branch_name += three_dots;
674
+ }
675
+ branch_name
676
+ }
677
+
638
678
/// Get branches to display
639
679
fn get_text (
640
680
& self ,
@@ -648,20 +688,15 @@ impl BranchListPopup {
648
688
const EMPTY_SYMBOL : char = ' ' ;
649
689
const THREE_DOTS : & str = "..." ;
650
690
const THREE_DOTS_LENGTH : usize = THREE_DOTS . len ( ) ; // "..."
651
- const COMMIT_HASH_LENGTH : usize = 8 ;
652
- const COMMIT_DATE_LENGTH : usize = 11 ;
653
- const IS_HEAD_STAR_LENGTH : usize = 3 ; // "* "
654
691
655
692
let branch_name_length: usize =
656
693
width_available as usize * 40 / 100 ;
657
694
// commit message takes up the remaining width
658
- let mut commit_message_length: usize = ( width_available
659
- as usize )
660
- . saturating_sub ( COMMIT_HASH_LENGTH )
661
- . saturating_sub ( COMMIT_DATE_LENGTH )
662
- . saturating_sub ( branch_name_length)
663
- . saturating_sub ( IS_HEAD_STAR_LENGTH )
664
- . saturating_sub ( THREE_DOTS_LENGTH ) ;
695
+ let shared_commit_message_length: usize =
696
+ Self :: calculate_shared_commit_message_length (
697
+ width_available,
698
+ THREE_DOTS_LENGTH ,
699
+ ) ;
665
700
let mut txt = Vec :: new ( ) ;
666
701
667
702
for ( i, displaybranch) in self
@@ -678,8 +713,7 @@ impl BranchListPopup {
678
713
let author_text =
679
714
displaybranch. top_commit_author . clone ( ) + " " ;
680
715
681
- // commit_message_length contains author_text length
682
- commit_message_length = commit_message_length
716
+ let commit_message_length = shared_commit_message_length
683
717
. saturating_sub ( author_text. len ( ) ) ;
684
718
let mut commit_message =
685
719
displaybranch. top_commit_message . clone ( ) ;
@@ -691,20 +725,12 @@ impl BranchListPopup {
691
725
commit_message += THREE_DOTS ;
692
726
}
693
727
694
- let mut branch_name = displaybranch. name . clone ( ) ;
695
- if branch_name. len ( )
696
- > branch_name_length. saturating_sub ( THREE_DOTS_LENGTH )
697
- {
698
- branch_name = branch_name
699
- . unicode_truncate (
700
- branch_name_length
701
- . saturating_sub ( THREE_DOTS_LENGTH ) ,
702
- )
703
- . 0
704
- . to_string ( ) ;
705
- branch_name += THREE_DOTS ;
706
- }
707
-
728
+ let branch_name = Self :: get_branch_name_text (
729
+ branch_name_length,
730
+ displaybranch,
731
+ THREE_DOTS_LENGTH ,
732
+ THREE_DOTS ,
733
+ ) ;
708
734
let selected = ( self . selection as usize
709
735
- self . scroll . get_top ( ) )
710
736
== i;
@@ -751,7 +777,6 @@ impl BranchListPopup {
751
777
format ! ( "{branch_name:branch_name_length$} " ) ,
752
778
theme. branch ( selected, is_head) ,
753
779
) ;
754
-
755
780
txt. push ( Line :: from ( vec ! [
756
781
span_prefix,
757
782
span_name,
@@ -761,7 +786,6 @@ impl BranchListPopup {
761
786
span_msg,
762
787
] ) ) ;
763
788
}
764
-
765
789
Text :: from ( txt)
766
790
}
767
791
0 commit comments