Fix linewrapper ellipsis inifinite loop (#779)

This commit is contained in:
Oleksandr Martyshchenko 2018-06-29 18:54:15 +03:00 committed by alafr
parent f91bdd61c1
commit 56c7debb89

View File

@ -146,12 +146,16 @@ class LineWrapper extends EventEmitter
textWidth = @wordWidth buffer + @ellipsis
# remove characters from the buffer until the ellipsis fits
while textWidth > @lineWidth
# to avoid inifinite loop need to stop while-loop if buffer is empty string
while buffer and textWidth > @lineWidth
buffer = buffer.slice(0, -1).replace(/\s+$/, '')
textWidth = @wordWidth buffer + @ellipsis
buffer = buffer + @ellipsis
# need to add ellipsis only if there is enough space for it
if textWidth <= @lineWidth
buffer = buffer + @ellipsis
textWidth = @wordWidth buffer
if bk.required
if w > @spaceLeft
emitLine()