From 92446bda805ed58a19ffea91babe209cb61b73c4 Mon Sep 17 00:00:00 2001 From: axel Date: Fri, 13 Oct 2006 02:13:17 +1000 Subject: [PATCH] Yet another tweak to the move_word function darcs-hash:20061012161317-ac50b-3b374e2b6c4c22f82c1cf018bf83298c8216fcb1.gz --- reader.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/reader.c b/reader.c index aa30c5e4c..371d1b852 100644 --- a/reader.c +++ b/reader.c @@ -1531,6 +1531,19 @@ static void move_word( int dir, int erase ) int end_buff_pos=data->buff_pos; 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 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--; } + + /* + When moving left, ignore the character under the cursor + */ + if( !dir ) + { + end_buff_pos+=2*step; + } /* Remove all whitespace characters before finding a word @@ -1578,7 +1599,6 @@ static void move_word( int dir, int erase ) end_buff_pos+=step; - } /* @@ -1598,23 +1618,31 @@ static void move_word( int dir, int erase ) if( end_buff_pos == data->buff_len ) break; } - + c = data->buff[end_buff_pos]; - + if( !iswalnum( c ) ) { /* - Don't gobble the boundary character if it was a - whitespace, but do for all other non-alphabetic - characters + Don't gobble the boundary character when moving to the + right */ - if( iswspace( c ) /* && ( abs( end_buff_pos-data->buff_pos ) > 1 ) */ && (step < 0)) + if( !dir ) end_buff_pos -= step; break; } 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 ) { int remove_count = abs(data->buff_pos - end_buff_pos);