File tree Expand file tree Collapse file tree 3 files changed +13
-6
lines changed
Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -897,6 +897,15 @@ describe('layout invariants', () => {
897897 expect ( reconstructFromLineBoundaries ( prepared , result . lines ) ) . toBe ( 'foo trans\u00ADatlantic' )
898898 } )
899899
900+ test ( 'soft-hyphen fallback does not crash when overflow happens on a later space' , ( ) => {
901+ const prepared = prepareWithSegments ( 'foo trans\u00ADatlantic labels' , FONT )
902+ const width = measureWidth ( 'foo transatlantic' , FONT ) + 0.1
903+ const result = layoutWithLines ( prepared , width , LINE_HEIGHT )
904+
905+ expect ( result . lines . map ( line => line . text ) ) . toEqual ( [ 'foo transatlantic ' , 'labels' ] )
906+ expect ( layout ( prepared , width , LINE_HEIGHT ) . lineCount ) . toBe ( result . lineCount )
907+ } )
908+
900909 test ( 'layoutNextLine variable-width streaming stays contiguous and reconstructs normalized text' , ( ) => {
901910 const prepared = prepareWithSegments (
902911 'foo trans\u00ADatlantic said "hello" to 世界 and waved. According to محمد الأحمد, alpha\u200Bbeta 🚀' ,
Original file line number Diff line number Diff line change @@ -466,7 +466,8 @@ export function walkPreparedLines(
466466
467467 function continueSoftHyphenBreakableSegment ( segmentIndex : number ) : boolean {
468468 if ( pendingBreakKind !== 'soft-hyphen' ) return false
469- const fitWidths = breakableFitAdvances [ segmentIndex ] !
469+ const fitWidths = breakableFitAdvances [ segmentIndex ]
470+ if ( fitWidths == null ) return false
470471 const { fitCount, fittedWidth } = fitSoftHyphenBreak (
471472 fitWidths ,
472473 lineW ,
Original file line number Diff line number Diff line change @@ -227,18 +227,15 @@ export function getSegmentBreakableFitAdvances(
227227 return metrics . breakableFitAdvances
228228 }
229229
230- const ctx = getMeasureContext ( )
231230 const advances : number [ ] = [ ]
232231 const graphemeSegmenter = getSharedGraphemeSegmenter ( )
233232 let prefix = ''
234233 let prefixWidth = 0
235- let prefixEmojiCount = 0
236234
237235 for ( const gs of graphemeSegmenter . segment ( seg ) ) {
238236 prefix += gs . segment
239- if ( emojiCorrection !== 0 && isEmojiGrapheme ( gs . segment ) ) prefixEmojiCount ++
240-
241- const nextPrefixWidth = ctx . measureText ( prefix ) . width - prefixEmojiCount * emojiCorrection
237+ const prefixMetrics = getSegmentMetrics ( prefix , cache )
238+ const nextPrefixWidth = getCorrectedSegmentWidth ( prefix , prefixMetrics , emojiCorrection )
242239 advances . push ( nextPrefixWidth - prefixWidth )
243240 prefixWidth = nextPrefixWidth
244241 }
You can’t perform that action at this time.
0 commit comments