File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed
components/conversation/message/message-content/quote Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { GoogleChrome } from '../../../../../util';
1010import { MessageBody } from '../MessageBody' ;
1111import { QuoteProps } from './Quote' ;
1212import { tr } from '../../../../../localization/localeTools' ;
13+ import { collapseString } from '../../../../../shared/string_utils' ;
1314
1415const StyledQuoteText = styled . div < { $isIncoming : boolean } > `
1516 display: -webkit-box;
@@ -72,12 +73,9 @@ export function getShortenedFilename(fileName: string) {
7273 if ( ! fileName ) {
7374 return '' ;
7475 }
75- if ( fileName ?. length < 20 ) {
76- return fileName ;
77- }
7876 const charsAround = 15 ;
7977
80- return ` ${ fileName . slice ( 0 , charsAround ) } … ${ fileName . slice ( - charsAround ) } ` ;
78+ return collapseString ( fileName , charsAround , charsAround , true ) ;
8179}
8280
8381export const QuoteText = (
Original file line number Diff line number Diff line change @@ -9,21 +9,24 @@ export function uniqFromListOfList<T extends string>(list: Array<Array<T>>): Arr
99
1010/**
1111 * Collapses a string by replacing characters between the leading and trailing characters with a triple ellipsis unicode character (length 1).
12- * The final length of the string will be the sum of the leading and trailing characters plus 1.
12+ * The final length of the string will be the sum of the leading and trailing characters plus 1 (or 3 if spacesAroundEllipsis is true) .
1313 * @param str - The input string to collapse.
1414 * @param leadingChars - The number of characters to keep at the beginning of the string.
1515 * @param trailingChars - The number of characters to keep at the end of the string.
16+ * @param spacesAroundEllipsis - Whether to add spaces around the ellipsis.
1617 * @param separator - The separator to use between the leading and trailing characters.
1718 * @returns The collapsed string.
1819 */
1920export const collapseString = (
2021 str : string ,
2122 leadingChars = 6 ,
2223 trailingChars = 4 ,
24+ spacesAroundEllipsis = false ,
2325 separator = '…'
2426) : string => {
25- if ( str . length <= leadingChars + trailingChars + 3 ) {
27+ if ( str . length <= leadingChars + trailingChars + 1 + ( spacesAroundEllipsis ? 2 : 0 ) ) {
2628 return str ;
2729 }
28- return `${ str . slice ( 0 , leadingChars ) } ${ separator } ${ str . slice ( - trailingChars ) } ` ;
30+ const ellipsis = spacesAroundEllipsis ? ` ${ separator } ` : separator ;
31+ return `${ str . slice ( 0 , leadingChars ) } ${ ellipsis } ${ str . slice ( - trailingChars ) } ` ;
2932} ;
You can’t perform that action at this time.
0 commit comments