Yet another tweak to the move_word function

darcs-hash:20061012161317-ac50b-3b374e2b6c4c22f82c1cf018bf83298c8216fcb1.gz
This commit is contained in:
axel 2006-10-13 02:13:17 +10:00
parent a620a1e5ed
commit 92446bda80

View file

@ -1531,6 +1531,19 @@ static void move_word( int dir, int erase )
int end_buff_pos=data->buff_pos; int end_buff_pos=data->buff_pos;
int step = dir?1:-1; int step = dir?1:-1;
/*
Return if we are already at the edge
*/
if( !dir && data->buff_pos == 0 )
{
return;
}
if( dir && data->buff_pos == data->buff_len )
{
return;
}
/* /*
If we are beyond the last character and moving left, start by If we are beyond the last character and moving left, start by
moving one step, since otehrwise we'll start on the \0, which moving one step, since otehrwise we'll start on the \0, which
@ -1543,6 +1556,14 @@ static void move_word( int dir, int erase )
end_buff_pos--; end_buff_pos--;
} }
/*
When moving left, ignore the character under the cursor
*/
if( !dir )
{
end_buff_pos+=2*step;
}
/* /*
Remove all whitespace characters before finding a word Remove all whitespace characters before finding a word
@ -1578,7 +1599,6 @@ static void move_word( int dir, int erase )
end_buff_pos+=step; end_buff_pos+=step;
} }
/* /*
@ -1598,23 +1618,31 @@ static void move_word( int dir, int erase )
if( end_buff_pos == data->buff_len ) if( end_buff_pos == data->buff_len )
break; break;
} }
c = data->buff[end_buff_pos]; c = data->buff[end_buff_pos];
if( !iswalnum( c ) ) if( !iswalnum( c ) )
{ {
/* /*
Don't gobble the boundary character if it was a Don't gobble the boundary character when moving to the
whitespace, but do for all other non-alphabetic right
characters
*/ */
if( iswspace( c ) /* && ( abs( end_buff_pos-data->buff_pos ) > 1 ) */ && (step < 0)) if( !dir )
end_buff_pos -= step; end_buff_pos -= step;
break; break;
} }
end_buff_pos+=step; end_buff_pos+=step;
} }
/*
Make sure we move at least one character
*/
if( end_buff_pos==data->buff_pos )
{
end_buff_pos+=step;
}
if( erase ) if( erase )
{ {
int remove_count = abs(data->buff_pos - end_buff_pos); int remove_count = abs(data->buff_pos - end_buff_pos);