File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1004,6 +1004,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
10041004 isActive : props . isActive ,
10051005 } ) ;
10061006
1007+ const titleDirection = textDirection ( thread . title ) ;
10071008 const title = isRenaming ? (
10081009 < ThreadRenameInput
10091010 title = { renamingTitle }
@@ -1038,9 +1039,15 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
10381039 ) ,
10391040 isRegeneratingTitle && "opacity-55" ,
10401041 ) }
1041- dir = { textDirection ( thread . title ) }
1042+ dir = { titleDirection }
10421043 >
1043- { thread . title }
1044+ { /* The measured cut assumes left-to-right text, so RTL titles keep their end ellipsis. */ }
1045+ < MiddleTruncate
1046+ value = { thread . title }
1047+ { ...( titleDirection === "rtl" ? { tail : 0 } : { } ) }
1048+ showTitle = { false }
1049+ className = "flex"
1050+ />
10441051 </ span >
10451052 ) ;
10461053 const accessibleTitle = isRenaming ? null : < span className = "sr-only" > { thread . title } </ span > ;
@@ -1736,7 +1743,12 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props
17361743 thread . titleRegeneration != null && "opacity-55" ,
17371744 ) }
17381745 >
1739- { thread . title }
1746+ < MiddleTruncate
1747+ value = { thread . title }
1748+ { ...( textDirection ( thread . title ) === "rtl" ? { tail : 0 } : { } ) }
1749+ showTitle = { false }
1750+ className = "flex"
1751+ />
17401752 </ span >
17411753 < span id = { `${ props . resultId } -pr` } className = "contents" >
17421754 < ThreadSearchPullRequestNumber
Original file line number Diff line number Diff line change @@ -23,6 +23,17 @@ describe("splitForMiddleTruncate", () => {
2323 expect ( splitForMiddleTruncate ( "t3/abcdefghijklmnopqrstuvwxyz" ) ?. tail ) . toBe ( "qrstuvwxyz" ) ;
2424 } ) ;
2525
26+ it ( "starts a title's tail on a word" , ( ) => {
27+ expect ( splitForMiddleTruncate ( "Debate Weaknesses in Bilateral Agreements" ) ) . toEqual ( {
28+ head : "Debate Weaknesses in Bilateral " ,
29+ tail : "Agreements" ,
30+ } ) ;
31+ } ) ;
32+
33+ it ( "flattens line breaks so a value stays on one line" , ( ) => {
34+ expect ( splitForMiddleTruncate ( "first\nsecond line of a label" ) ?. head ) . not . toContain ( "\n" ) ;
35+ } ) ;
36+
2637 it ( "respects an explicit tail length" , ( ) => {
2738 expect ( splitForMiddleTruncate ( "t3/clone-repo-to-other-machine" , 6 ) ?. tail ) . toBe ( "achine" ) ;
2839 } ) ;
Original file line number Diff line number Diff line change @@ -42,10 +42,12 @@ export function MiddleTruncate({
4242 { split ? (
4343 < >
4444 { /* The tail carries the ellipsis so it sits flush; a CSS ellipsis leaves a ragged gap. */ }
45- < span ref = { headRef } className = "peer min-w-0 overflow-hidden" >
45+ < span ref = { headRef } className = "peer min-w-0 overflow-hidden whitespace-pre " >
4646 { split . head }
4747 </ span >
48- < span className = "shrink-0 peer-data-overflow:before:content-['…']" > { split . tail } </ span >
48+ < span className = "shrink-0 whitespace-pre peer-data-overflow:before:content-['…']" >
49+ { split . tail }
50+ </ span >
4951 </ >
5052 ) : (
5153 // Keyed so React does not reuse the head node and its imperative clip.
@@ -92,14 +94,14 @@ function fitHead(head: HTMLElement) {
9294const DEFAULT_TAIL = 10 ;
9395const MAX_SEGMENT_TAIL = 16 ;
9496const MIN_WORD_TAIL = 4 ;
95- const WORD_BREAK = / [ - _ . / ] / ;
97+ const WORD_BREAK = / [ - _ . / \s ] / ;
9698
9799export function splitForMiddleTruncate (
98100 value : string ,
99101 tail ?: number ,
100102) : { head : string ; tail : string } | null {
101103 // Split by code point to avoid cutting surrogate pairs into broken glyphs.
102- const chars = Array . from ( value ) ;
104+ const chars = Array . from ( value . replace ( / [ \r \n ] + / g , " " ) ) ;
103105 let keep = tail ?? DEFAULT_TAIL ;
104106 if ( tail === undefined ) {
105107 const slash = chars . lastIndexOf ( "/" ) ;
You can’t perform that action at this time.
0 commit comments