From 2c28a22971f837c58c8adbd7f5a5660328f9b43a Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Tue, 28 Aug 2018 10:56:52 -0500 Subject: [PATCH] text: prepare to make find_paragraph() work on any buffer Move a few references to the current buffer to do_justify(). Also, the check for being at the end of the buffer needs to be done after the first paragraph is found, so that the existing behavior of finding an initial paragraph regardless of cursor position is preserved. --- src/text.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/text.c b/src/text.c index 442efe95..5cba602e 100644 --- a/src/text.c +++ b/src/text.c @@ -2122,12 +2122,6 @@ bool find_paragraph(size_t *const quote, size_t *const par) return FALSE; } - /* If we're at the end of the last line of the file, it means that - * there aren't any paragraphs left, so get out. */ - if (openfile->current == openfile->filebot && openfile->current_x == - strlen(openfile->filebot->data)) - return FALSE; - /* If the current line isn't in a paragraph, move forward to the * last line of the next paragraph, if any. */ if (!inpar(openfile->current)) { @@ -2331,14 +2325,11 @@ void do_justify(bool full_justify) size_t current_x_save = openfile->current_x; bool modified_save = openfile->modified; - /* Move to the beginning of the current line, so that justifying at - * the end of the last line of the file, if that line isn't blank, - * will work the first time through. */ - openfile->current_x = 0; - /* If we're justifying the entire file, start at the beginning. */ - if (full_justify) + if (full_justify) { openfile->current = openfile->fileage; + openfile->current_x = 0; + } /* Find the first line of the paragraph(s) to be justified. * If the search failed, it means that there are no paragraph(s) to @@ -2375,6 +2366,12 @@ void do_justify(bool full_justify) if (filebot_inpar) openfile->current_x = strlen(openfile->current->data); + /* If we're at the end of the last line of the file, it means that + * there aren't any paragraphs left, so break out of the loop. */ + if (openfile->current == openfile->filebot && openfile->current_x == + strlen(openfile->filebot->data)) + break; + /* If we're justifying the entire file, * find the next line of the paragraph(s) to be justified. * If the search failed, it means that there are no paragraph(s) to