justification fix: if the last line of a justified paragraph has a space

on the end of it, the space should be removed


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1804 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-06-05 22:09:56 +00:00
parent 7ea39efdbd
commit a9a6ce09d6
2 changed files with 21 additions and 9 deletions

View File

@ -42,9 +42,10 @@ CVS code -
feature is disabled if justification is disabled. (DLR)
- Modify the justification algorithm to work the same way as in
the current version of Pico, i.e, add a space at the end of
each line of the justified paragraph except for the last one.
Changes to justify_format() and do_justify(). (Note that the
addition of spaces to justified lines means that
each line of the justified paragraph except for the last one,
and if there was a space at the end of the last one, remove
it. Changes to justify_format() and do_justify(). (Note that
the addition of spaces to justified lines means that
first_mod_line can no longer be used to reliably detect the
first modified line in a paragraph, since a line unmodified by
justify_format() may get a space tacked onto the end of it

View File

@ -2594,14 +2594,25 @@ int do_justify(int full_justify)
/* If the line we were on before still exists, and it was
* not the last line of the paragraph, add a space to the
* end of it to replace the one removed or left out by
* justify_format(). */
if (current->prev != NULL && par_len > 1) {
* justify_format(). If it was the last line of the
* paragraph, and justify_format() left a space on the end
* of it, remove the space. */
if (current->prev != NULL) {
size_t prev_line_len = strlen(current->prev->data);
current->prev->data = charealloc(current->prev->data,
if (par_len > 1) {
current->prev->data = charealloc(current->prev->data,
prev_line_len + 2);
current->prev->data[prev_line_len] = ' ';
current->prev->data[prev_line_len + 1] = '\0';
totsize++;
current->prev->data[prev_line_len] = ' ';
current->prev->data[prev_line_len + 1] = '\0';
totsize++;
} else if (par_len == 1 &&
current->prev->data[prev_line_len - 1] == ' ') {
current->prev->data = charealloc(current->prev->data,
prev_line_len);
current->prev->data[prev_line_len - 1] = '\0';
totsize--;
}
}
}