From 81dea02ca7d5461c20db3e8c360efc9353cff12f Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Sat, 21 Sep 2002 02:19:45 +0000 Subject: [PATCH] Add DLR's fixes to the wrapping behavior git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1282 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 2 +- nano.c | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22014093..8cdbb708 100644 --- a/ChangeLog +++ b/ChangeLog @@ -95,7 +95,7 @@ CVS code - characters on the line is exactly one over the limit. (David Benbennick) - Restore the previous wrapping point behavior (pre 1.1.10) - (David Benbennick). + (David Benbennick, fixes by DLR). do_alt_speller() - Readd DLR's fix to preserve marking when using the alternate spell checker; it was accidentally dropped. (David diff --git a/nano.c b/nano.c index e73cadba..0cfdb709 100644 --- a/nano.c +++ b/nano.c @@ -1479,13 +1479,13 @@ int do_wrap(filestruct *inptr) #ifndef NANO_SMALL if (ISSET(AUTOINDENT)) { - /* indentation comes from the next line if wrapping, else from - * this line */ + /* Indentation comes from the next line if wrapping, else from + * this line. */ indentation = (wrapping ? wrap_line : inptr->data); indent_len = indent_length(indentation); if (wrapping) - /* The wrap_line text should not duplicate indentation. Note - * in this case we need not increase new_line_len. */ + /* The wrap_line text should not duplicate indentation. + * Note in this case we need not increase new_line_len. */ wrap_line += indent_len; else new_line_len += indent_len; @@ -1504,13 +1504,18 @@ int do_wrap(filestruct *inptr) #endif strcat(newline, after_break); /* We end the old line after wrap_loc. Note this does not eat the - space. */ + * space. */ null_at(&inptr->data, wrap_loc + 1); totsize++; if (wrapping) { /* In this case, totsize increases by 1 since we add a space - between after_break and wrap_line. */ - strcat(newline, " "); + * between after_break and wrap_line. If the line already ends + * in a space, we don't add a space and decrement totsize to + * account for that. */ + if (newline[strlen(newline) - 1] != ' ') + strcat(newline, " "); + else + totsize--; strcat(newline, wrap_line); free(inptr->next->data); inptr->next->data = newline; @@ -1518,7 +1523,7 @@ int do_wrap(filestruct *inptr) filestruct *temp = (filestruct *)nmalloc(sizeof(filestruct)); /* In this case, the file size changes by +1 for the new line, and - +indent_len for the new indentation. */ + * +indent_len for the new indentation. */ #ifndef NANO_SMALL totsize += indent_len; #endif @@ -1528,7 +1533,7 @@ int do_wrap(filestruct *inptr) temp->next = inptr->next; temp->prev->next = temp; /* If !temp->next, then temp is the last line of the file, so we - * must set filebot */ + * must set filebot. */ if (temp->next) temp->next->prev = temp; else