@@ -34,6 +34,13 @@ const ACTIVITY_MAX_LENGTH = 120;
3434// Parsing is synchronous, and nobody listens to a longer message through a live region.
3535const MESSAGE_MAX_LENGTH = 2_000 ;
3636
37+ /** The first `maxLength` code points of `text`, or null when it has no more than that. */
38+ function cutText ( text : string , maxLength : number ) : string | null {
39+ if ( text . length <= maxLength ) return null ;
40+ const characters = Array . from ( text ) ;
41+ return characters . length > maxLength ? characters . slice ( 0 , maxLength ) . join ( "" ) : null ;
42+ }
43+
3744// On screen these labels are a path or a query beside an icon.
3845function withVerb ( work : WorkLogEntry , label : string ) {
3946 if ( work . itemType === "file_change" ) return `Editing ${ label } ` ;
@@ -66,7 +73,8 @@ function stepLabel(work: WorkLogEntry, workspaceRoot: string | undefined): strin
6673 const label = liveWorkEntryLabel ( work , workspaceRoot , true ) . replace ( / \s + / g, " " ) . trim ( ) ;
6774 if ( label === "" ) return null ;
6875 const spoken = withVerb ( work , label ) ;
69- return spoken . length > ACTIVITY_MAX_LENGTH ? `${ spoken . slice ( 0 , ACTIVITY_MAX_LENGTH ) } …` : spoken ;
76+ const cut = cutText ( spoken , ACTIVITY_MAX_LENGTH ) ;
77+ return cut === null ? spoken : `${ cut } …` ;
7078}
7179
7280/**
@@ -189,11 +197,12 @@ export function nextTurnDetailAnnouncement(
189197 previous . messages . get ( message . id ) !== true &&
190198 ( message . fresh || previous . messages . has ( message . id ) ) ,
191199 )
192- . map ( ( message ) =>
193- message . text . length > MESSAGE_MAX_LENGTH
194- ? `${ markdownPlainText ( message . text . slice ( 0 , MESSAGE_MAX_LENGTH ) ) } More in the thread.`
195- : markdownPlainText ( message . text ) ,
196- )
200+ . map ( ( message ) => {
201+ const cut = cutText ( message . text , MESSAGE_MAX_LENGTH ) ;
202+ return cut === null
203+ ? markdownPlainText ( message . text )
204+ : `${ markdownPlainText ( cut ) } More in the thread.` ;
205+ } )
197206 . filter ( ( text ) => text !== "" )
198207 . map ( ( text ) => `${ MESSAGE_AUTHOR } : ${ text } ` ) ,
199208 activity :
0 commit comments