- do_wrap() needs to keep spaces when you are on the first word that should be wrapped and hit a

space while the cursor is on the first character, but delete spaces when it's the second
  character or anything else that follows.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@33 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Adam Rogoyski 2000-06-19 17:30:14 +00:00
parent 68576d31d4
commit 3d449b4142
1 changed files with 18 additions and 24 deletions

28
nano.c
View File

@ -611,7 +611,7 @@ assert (strlenpt(inptr->data) >= fill);
assert (current_word_end_t >= fill); assert (current_word_end_t >= fill);
/* There are a few 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.
* a) one word takes up the whole line with no starting spaces. * a) one word takes up the whole line with no starting spaces.
* - do nothing and return. * - do nothing and return.
@ -622,20 +622,18 @@ assert (strlenpt(inptr->data) >= fill);
* - either it's all white space after word, and this routine isn't called. * - either it's all white space after word, and this routine isn't called.
* - or we are actually in case 2 (2 words). * - or we are actually in case 2 (2 words).
* 2) Two or more words on the line before wrap point. * 2) Two or more words on the line before wrap point.
* a) cursor is at a word before wrap point * a) cursor is at a word or space before wrap point
* - word at wrap point starts a new line. * - word at wrap point starts a new line.
* - white space at end of original line is cleared. * - white space at end of original line is cleared, unless
* it is all spaces between previous word and next word which appears after fill.
* b) cursor is at the word at the wrap point. * b) cursor is at the word at the wrap point.
* - word at wrap point starts a new line. * - word at wrap point starts a new line.
* 1. pressed a space. * 1. pressed a space and at first character of wrap point word.
* - white space on original line is kept to where cursor was. * - white space on original line is kept to where cursor was.
* 2. pressed non space. * 2. pressed non space (or space elsewhere).
* - white space at end of original line is cleared. * - white space at end of original line is cleared.
* c) cursor is past the word at the wrap point. * c) cursor is past the word at the wrap point.
* - word at wrap point starts a new line. * - word at wrap point starts a new line.
* 1. pressed a space.
* - white space on original line is kept to where wrap point was.
* 2. pressed a non space.
* - white space at end of original line is cleared * - white space at end of original line is cleared
*/ */
@ -701,11 +699,15 @@ assert (strlenpt(inptr->data) >= fill);
temp->data = nmalloc(strlen(&inptr->data[current_word_start]) + 1); temp->data = nmalloc(strlen(&inptr->data[current_word_start]) + 1);
strcpy(temp->data, &inptr->data[current_word_start]); strcpy(temp->data, &inptr->data[current_word_start]);
if (!isspace(input_char)) {
i = current_word_start - 1; i = current_word_start - 1;
while (isspace(inptr->data[i])) { while (isspace(inptr->data[i])) {
i--; i--;
assert (i >= 0); assert (i >= 0);
} }
}
else
i = current_x - 1;
inptr->data = nrealloc(inptr->data, i + 2); inptr->data = nrealloc(inptr->data, i + 2);
inptr->data[i + 1] = 0; inptr->data[i + 1] = 0;
@ -722,7 +724,7 @@ assert (strlenpt(inptr->data) >= fill);
right = current_x - current_word_start; right = current_x - current_word_start;
i = current_word_start - 1; i = current_word_start - 1;
if (isspace(input_char)) { if (isspace(input_char) && (current_x == current_word_start)) {
current_x = current_word_start; current_x = current_word_start;
inptr->data = nrealloc(inptr->data, current_word_start + 1); inptr->data = nrealloc(inptr->data, current_word_start + 1);
@ -737,7 +739,6 @@ assert (strlenpt(inptr->data) >= fill);
inptr->data = nrealloc(inptr->data, i + 2); inptr->data = nrealloc(inptr->data, i + 2);
inptr->data[i + 1] = 0; inptr->data[i + 1] = 0;
} }
} }
@ -752,16 +753,9 @@ assert (strlenpt(inptr->data) >= fill);
current_x = current_word_start; current_x = current_word_start;
i = current_word_start - 1; i = current_word_start - 1;
if (isspace(input_char)) {
inptr->data = nrealloc(inptr->data, current_word_start + 1);
inptr->data[current_word_start] = 0;
}
else {
while (isspace(inptr->data[i])) { while (isspace(inptr->data[i])) {
i--; i--;
assert (i >= 0); assert (i >= 0);
}
inptr->data = nrealloc(inptr->data, i + 2); inptr->data = nrealloc(inptr->data, i + 2);
inptr->data[i + 1] = 0; inptr->data[i + 1] = 0;
} }