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
/* 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--;
+ }
}
}