@@ -181,32 +181,35 @@ export const wrapText = (
181
181
maxLineLength : number ,
182
182
lineBreak : string ,
183
183
) : string => {
184
+ if ( ! text . includes ( ' ' ) ) {
185
+ return `${ linePrefix } ${ text } ` ;
186
+ }
184
187
let wrappedText = linePrefix + text ;
185
- let nextLineStartIndex = 0 ;
186
- while ( wrappedText . length - nextLineStartIndex > maxLineLength ) {
188
+ let currentLineStartIndex = 0 ;
189
+ while ( wrappedText . length - currentLineStartIndex > maxLineLength ) {
187
190
const overflowingCharacterIndex = Math . min (
188
- nextLineStartIndex + maxLineLength - 1 ,
191
+ currentLineStartIndex + maxLineLength - 1 ,
189
192
wrappedText . length ,
190
193
) ;
191
- for ( let i = overflowingCharacterIndex ; i >= nextLineStartIndex ; i -- ) {
194
+ for ( let i = overflowingCharacterIndex ; i >= currentLineStartIndex ; i -- ) {
192
195
const char = wrappedText [ i ] ;
193
196
if ( char === ' ' ) {
194
197
wrappedText =
195
198
wrappedText . slice ( 0 , i ) +
196
199
lineBreak +
197
200
linePrefix +
198
201
wrappedText . slice ( i + 1 ) ;
199
- nextLineStartIndex = lineBreak . length + linePrefix . length + i ;
202
+ currentLineStartIndex = lineBreak . length + linePrefix . length + i ;
200
203
break ;
201
204
}
202
- if ( i === nextLineStartIndex ) {
203
- const nextSpaceIndex = wrappedText . indexOf ( ' ' , nextLineStartIndex ) ;
205
+ if ( i === currentLineStartIndex ) {
206
+ const nextSpaceIndex = wrappedText . indexOf ( ' ' , currentLineStartIndex ) ;
204
207
wrappedText =
205
208
wrappedText . slice ( 0 , nextSpaceIndex ) +
206
209
lineBreak +
207
210
linePrefix +
208
211
wrappedText . slice ( nextSpaceIndex + 1 ) ;
209
- nextLineStartIndex =
212
+ currentLineStartIndex =
210
213
lineBreak . length + linePrefix . length + nextSpaceIndex ;
211
214
}
212
215
}
0 commit comments