1
1

- check_wrap() more off by one.

- do_justify() off by 1 and off by 2, and fix numbering and handling off bottom line.

   Wrapping and justify should now do the same thing and agree on what where to wrap everything.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@40 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
Adam Rogoyski 2000-06-20 02:50:33 +00:00
родитель 790198d33c
Коммит 09f9796b85

67
nano.c
Просмотреть файл

@ -582,7 +582,7 @@ void do_wrap(filestruct *inptr, char input_char)
int right = 0; int right = 0;
struct filestruct *temp = NULL; struct filestruct *temp = NULL;
assert (strlenpt(inptr->data) >= fill); assert (strlenpt(inptr->data) > fill);
for (i = 0, i_tabs = 0; i < len; i++, i_tabs++) { for (i = 0, i_tabs = 0; i < len; i++, i_tabs++) {
if (!isspace(inptr->data[i])) { if (!isspace(inptr->data[i])) {
@ -613,11 +613,11 @@ assert (strlenpt(inptr->data) >= fill);
i_tabs += TABSIZE - (i_tabs % TABSIZE); i_tabs += TABSIZE - (i_tabs % TABSIZE);
} }
if (current_word_end_t >= fill) if (current_word_end_t > fill)
break; break;
} }
assert (current_word_end_t >= fill); assert (current_word_end_t > fill);
/* There are a few (ever changing) cases of what the line could look like. /* There are a few (ever changing) cases of what the line could look like.
* 1) only one word on the line before wrap point. * 1) only one word on the line before wrap point.
@ -856,33 +856,28 @@ void check_wrap(filestruct * inptr, char ch)
int i = actual_x(inptr, fill); int i = actual_x(inptr, fill);
/* Do not wrap if there are no words on or after wrap point. */ /* Do not wrap if there are no words on or after wrap point. */
/* First check to see if we typed space and passed a word. */ int char_found = 0;
if (isspace(ch) && !isspace(inptr->data[i - 1]))
do_wrap(inptr, ch);
else {
int char_found = 0;
while (isspace(inptr->data[i]) && inptr->data[i]) while (isspace(inptr->data[i]) && inptr->data[i])
i++; i++;
if (!inptr->data[i]) if (!inptr->data[i])
return; return;
/* String must be at least 1 character long. */ /* String must be at least 1 character long. */
for (i = strlen(inptr->data) - 1; i >= 0; i--) { for (i = strlen(inptr->data) - 1; i >= 0; i--) {
if (isspace(inptr->data[i])) { if (isspace(inptr->data[i])) {
if (!char_found) if (!char_found)
continue; continue;
char_found = 2; /* 2 for yes do wrap. */ char_found = 2; /* 2 for yes do wrap. */
break; break;
}
else
char_found = 1; /* 1 for yes found a word, but must check further. */
} }
else
if (char_found == 2) char_found = 1; /* 1 for yes found a word, but must check further. */
do_wrap(inptr, ch);
} }
if (char_found == 2)
do_wrap(inptr, ch);
} }
} }
@ -1437,17 +1432,17 @@ int do_justify(void)
justify_format(current->data); justify_format(current->data);
slen = strlen(current->data); slen = strlen(current->data);
while ((strlenpt(current->data) > (fill + 1)) while ((strlenpt(current->data) > (fill))
&& !no_spaces(current->data)) { && !no_spaces(current->data)) {
int i = 0; int i = 0;
int len2 = 0; int len2 = 0;
filestruct *tmpline = nmalloc(sizeof(filestruct)); filestruct *tmpline = nmalloc(sizeof(filestruct));
/* Start at fill + 2, unless line isn't that long (but it appears at least /* Start at fill , unless line isn't that long (but it appears at least
* fill + 2 long with tabs. * fill long with tabs.
*/ */
if (slen > (fill + 2)) if (slen > fill)
i = fill + 2; i = fill;
else else
i = slen; i = slen;
for (; i > 0; i--) { for (; i > 0; i--) {
@ -1480,13 +1475,19 @@ int do_justify(void)
current_y++; current_y++;
} }
renumber(initial);
if (current->next) if (current->next)
current = current->next; current = current->next;
else
filebot = current;
current_x = 0; current_x = 0;
placewewant = 0; placewewant = 0;
renumber(initial);
totlines = filebot->lineno;
werase(edit);
if ((current_y < 0) || (current_y >= editwinrows - 1) || (initial_y <= 0)) { if ((current_y < 0) || (current_y >= editwinrows - 1) || (initial_y <= 0)) {
edit_update(current); edit_update(current);
center_cursor(); center_cursor();
@ -1497,9 +1498,11 @@ int do_justify(void)
for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL) for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
&& (editbot->next != filebot); i++) && (editbot->next != filebot); i++)
editbot = editbot->next; editbot = editbot->next;
edit_refresh();
} }
edit_refresh();
edit_refresh(); /* XXX FIXME XXX */
statusbar("Justify Complete"); statusbar("Justify Complete");
return 1; return 1;
#else #else