fix bug in do_justify(): if all the text from the next line has been

moved to the current line and the next line has been deleted, continue
the justification loop from there and skip the respacing routine in
order to avoid running it more than once on the same line (since it
assumes that we've moved to the next line, which isn't true in that
case)


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1839 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-07-03 05:23:19 +00:00
parent c8c69d5449
commit 01a6bf4f9a
2 changed files with 19 additions and 7 deletions

View File

@ -27,6 +27,13 @@ CVS code -
- Fix erroneous #ifdef so that nano compiles with - Fix erroneous #ifdef so that nano compiles with
--disable-justify again. (DLR; found by Mike Frysinger) --disable-justify again. (DLR; found by Mike Frysinger)
- nano.c: - nano.c:
do_justify()
- If all the text from the next line has been moved to the
current line and the next line has been deleted, continue the
justification loop from there and skip the respacing routine
in order to avoid running it more than once on the same line
(since it assumes that we've moved to the next line, which
isn't true in that case). (DLR)
do_exit() do_exit()
- Tweak for efficiency. (David Benbennick) - Tweak for efficiency. (David Benbennick)
- proto.h: - proto.h:

View File

@ -2407,7 +2407,6 @@ void do_justify(int full_justify)
last_par_line = current; last_par_line = current;
while (TRUE) { while (TRUE) {
/* First, search for the beginning of the current paragraph or, /* First, search for the beginning of the current paragraph or,
* if we're at the end of it, the beginning of the next * if we're at the end of it, the beginning of the next
* paragraph. Save the quote length, paragraph length, and * paragraph. Save the quote length, paragraph length, and
@ -2570,11 +2569,17 @@ void do_justify(int full_justify)
totlines--; totlines--;
totsize -= indent_len; totsize -= indent_len;
current_y--; current_y--;
/* Don't go to the next line, since there isn't one
* anymore. Just continue the loop from here. */
continue;
} else { } else {
charmove(current->next->data + indent_len, charmove(current->next->data + indent_len,
current->next->data + indent_len + break_pos + 1, current->next->data + indent_len + break_pos + 1,
next_line_len - break_pos - indent_len); next_line_len - break_pos - indent_len);
null_at(&current->next->data, next_line_len - break_pos); null_at(&current->next->data, next_line_len - break_pos);
/* Go to the next line. */
current = current->next; current = current->next;
} }
} else } else
@ -2582,12 +2587,12 @@ void do_justify(int full_justify)
/* Go to the next line. */ /* Go to the next line. */
current = current->next; current = current->next;
/* If the line we were on before still exists, and it was /* If we've gone to the next line, the line we were on
* not the last line of the paragraph, add a space to the * before still exists, and it was not the last line of the
* end of it to replace the one removed or left out by * paragraph, add a space to the end of it to replace the
* justify_format(). If it was the last line of the * one removed or left out by justify_format(). If it was
* paragraph, and justify_format() left a space on the end * the last line of the paragraph, and justify_format() left
* of it, remove the space. */ * a space on the end of it, remove the space. */
if (current->prev != NULL) { if (current->prev != NULL) {
size_t prev_line_len = strlen(current->prev->data); size_t prev_line_len = strlen(current->prev->data);