@@ -219,7 +219,7 @@ impl Component for BranchListPopup {
219219 strings:: commands:: sort_branch ( & self . key_config ) ,
220220 true ,
221221 true ,
222- ) )
222+ ) ) ;
223223 }
224224 visibility_blocking ( self )
225225 }
@@ -315,7 +315,7 @@ impl Component for BranchListPopup {
315315 ) ) ;
316316 } else if key_match ( e, self . key_config . keys . branch_sort ) {
317317 self . queue . push ( InternalEvent :: OpenBranchSortPopup (
318- self . sort_by . clone ( ) ,
318+ self . sort_by ,
319319 ) ) ;
320320 }
321321 }
@@ -480,10 +480,10 @@ impl BranchListPopup {
480480 } ) ;
481481 }
482482 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 ) ) ;
484484 }
485485 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 ) ) ;
487487 }
488488 }
489489 //remove remote branch called `HEAD`
@@ -635,6 +635,46 @@ impl BranchListPopup {
635635 Ok ( ( ) )
636636 }
637637
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+
638678 /// Get branches to display
639679 fn get_text (
640680 & self ,
@@ -648,20 +688,15 @@ impl BranchListPopup {
648688 const EMPTY_SYMBOL : char = ' ' ;
649689 const THREE_DOTS : & str = "..." ;
650690 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 ; // "* "
654691
655692 let branch_name_length: usize =
656693 width_available as usize * 40 / 100 ;
657694 // 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+ ) ;
665700 let mut txt = Vec :: new ( ) ;
666701
667702 for ( i, displaybranch) in self
@@ -678,8 +713,7 @@ impl BranchListPopup {
678713 let author_text =
679714 displaybranch. top_commit_author . clone ( ) + " " ;
680715
681- // commit_message_length contains author_text length
682- commit_message_length = commit_message_length
716+ let commit_message_length = shared_commit_message_length
683717 . saturating_sub ( author_text. len ( ) ) ;
684718 let mut commit_message =
685719 displaybranch. top_commit_message . clone ( ) ;
@@ -691,20 +725,12 @@ impl BranchListPopup {
691725 commit_message += THREE_DOTS ;
692726 }
693727
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+ ) ;
708734 let selected = ( self . selection as usize
709735 - self . scroll . get_top ( ) )
710736 == i;
@@ -751,7 +777,6 @@ impl BranchListPopup {
751777 format ! ( "{branch_name:branch_name_length$} " ) ,
752778 theme. branch ( selected, is_head) ,
753779 ) ;
754-
755780 txt. push ( Line :: from ( vec ! [
756781 span_prefix,
757782 span_name,
@@ -761,7 +786,6 @@ impl BranchListPopup {
761786 span_msg,
762787 ] ) ) ;
763788 }
764-
765789 Text :: from ( txt)
766790 }
767791
0 commit comments