nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 66cd897dc41536b2758c394c5e3d12434654b2fc
parent 67e6eee26e7a1e51681dccec804d0b3d127e10b0
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Sun, 25 Nov 2018 11:51:30 +0100

justify: correctly detect when we've reached end of buffer

When, in the 'while' loop for a full justify, 'filebot_inpar' becomes
TRUE, it means that EOF has been reached and find_paragraph() should
not be called again.  To allow 'filebot_inpar' to convey this meaning,
it should not be set to TRUE elsewhere, so another boolean is needed
for setting the correct length of the final line of the cutbuffer.

This fixes https://savannah.gnu.org/bugs/?55086.

Diffstat:
Msrc/text.c | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/text.c b/src/text.c @@ -2231,6 +2231,8 @@ void do_justify(bool full_justify) * paragraph(s), if any. */ bool filebot_inpar; /* Whether the text at filebot is part of the current paragraph. */ + bool text_on_last_line = FALSE; + /* Whether the last line of the buffer contains text. */ filestruct *was_cutbuffer = cutbuffer; /* The old cutbuffer, so we can justify in the current cutbuffer. */ @@ -2278,12 +2280,9 @@ void do_justify(bool full_justify) * last line of the file (counting the text at filebot). Otherwise, move * last_par_line down to the last line of the paragraph. */ if (full_justify) { - jus_len = openfile->filebot->lineno - first_par_line->lineno; - - if (openfile->filebot->data[0] != '\0') { - jus_len++; - filebot_inpar = TRUE; - } + text_on_last_line = (openfile->filebot->data[0] != '\0'); + jus_len = openfile->filebot->lineno - first_par_line->lineno + + (text_on_last_line ? 1 : 0); } else jus_len = par_len; @@ -2304,7 +2303,7 @@ void do_justify(bool full_justify) #endif /* Do the equivalent of a marked cut. */ extract_buffer(&cutbuffer, &cutbottom, first_par_line, 0, last_par_line, - filebot_inpar ? strlen(last_par_line->data) : 0); + filebot_inpar || text_on_last_line ? strlen(last_par_line->data) : 0); #ifndef NANO_TINY update_undo(CUT); #endif @@ -2318,7 +2317,8 @@ void do_justify(bool full_justify) /* If we're justifying the entire file, search for and justify paragraphs * until we can't anymore. */ if (full_justify) { - while (find_paragraph(&jusline, &filebot_inpar, &quote_len, &par_len)) + while (!filebot_inpar && + find_paragraph(&jusline, &filebot_inpar, &quote_len, &par_len)) justify_paragraph(&jusline, quote_len, par_len); }