From 841fdf3a0432bfbd96f5b6c953bacd0da39f7dd6 Mon Sep 17 00:00:00 2001 From: axel Date: Fri, 13 Oct 2006 05:30:00 +1000 Subject: [PATCH] Make kill-word and backward-kill-word accumulate kills in the killring darcs-hash:20061012193000-ac50b-69f261df78b3957b9cec3d728fe05b8a27267c31.gz --- reader.c | 64 +++++++++++++++++++------------------------------------- 1 file changed, 22 insertions(+), 42 deletions(-) diff --git a/reader.c b/reader.c index 371d1b852..ef2bb43d6 100644 --- a/reader.c +++ b/reader.c @@ -399,6 +399,18 @@ static void reader_kill( wchar_t *begin, int length, int mode, int new ) kill_replace( old, (wchar_t *)data->kill_item.buff ); free( old ); } + + if( data->buff_pos > (begin-data->buff) ) + { + data->buff_pos = maxi( begin-data->buff, data->buff_pos-length ); + } + + data->buff_len -= length; + memmove( begin, begin+length, sizeof( wchar_t )*(wcslen( begin+length )+1) ); + + reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); + repaint(); + } /** @@ -1039,10 +1051,6 @@ static void run_pager( wchar_t *prefix, int is_quoted, array_list_t *comp ) for( i=0; ibuff_pos; int step = dir?1:-1; @@ -1647,19 +1655,10 @@ static void move_word( int dir, int erase ) { int remove_count = abs(data->buff_pos - end_buff_pos); int first_char = mini( data->buff_pos, end_buff_pos ); - wchar_t *woot = wcsndup( data->buff + first_char, remove_count); // fwprintf( stderr, L"Remove from %d to %d\n", first_char, first_char+remove_count ); - - kill_add( woot ); - free( woot ); - memmove( data->buff + first_char, data->buff + first_char+remove_count, sizeof(wchar_t)*(data->buff_len-first_char-remove_count) ); - data->buff_len -= remove_count; - data->buff_pos = first_char; - data->buff[data->buff_len]=0; - - reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); - - repaint(); + + reader_kill( data->buff + first_char, remove_count, dir?KILL_APPEND:KILL_PREPEND, new ); + } else { @@ -2221,11 +2220,6 @@ wchar_t *reader_readline() reader_kill( begin, len, KILL_APPEND, last_char!=R_KILL_LINE ); - memmove( begin, end, sizeof( wchar_t )*(wcslen( end )+1) ); - data->buff_len -= len; - - reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); - repaint(); } break; @@ -2248,15 +2242,7 @@ wchar_t *reader_readline() len = maxi( end-begin, 1 ); begin = end - len; - reader_kill( begin, len, KILL_PREPEND, last_char!=R_BACKWARD_KILL_LINE ); - - memmove( begin, end, sizeof( wchar_t )*(wcslen( end )+1) ); - data->buff_pos -= len; - data->buff_len -= len; - - - reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); - repaint(); + reader_kill( begin, len, KILL_PREPEND, last_char!=R_BACKWARD_KILL_LINE ); } break; @@ -2292,12 +2278,6 @@ wchar_t *reader_readline() reader_kill( begin, len, KILL_APPEND, last_char!=R_KILL_WHOLE_LINE ); - memmove( begin, end, sizeof( wchar_t )*(wcslen( end )+1) ); - data->buff_pos = begin - data->buff; - data->buff_len -= len; - - reader_super_highlight_me_plenty( data->color, data->buff_pos, 0 ); - repaint(); } break; @@ -2534,28 +2514,28 @@ wchar_t *reader_readline() /* kill one word left */ case R_BACKWARD_KILL_WORD: { - move_word(0,1); + move_word(0,1, last_char!=R_BACKWARD_KILL_WORD); break; } /* kill one word right */ case R_KILL_WORD: { - move_word(1,1); + move_word(1,1, last_char!=R_KILL_WORD); break; } /* move one word left*/ case R_BACKWARD_WORD: { - move_word(0,0); + move_word(0,0,0); break; } /* move one word right*/ case R_FORWARD_WORD: { - move_word( 1,0); + move_word( 1,0,0); break; }