From 3020c5573d560daf20f99f9b8a5a19b31e89d5c9 Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Wed, 29 Apr 2009 07:06:27 +0000 Subject: [PATCH 1/2] fix UNDO: revert void edit_cursor_move to original. add void edit_right_char_move_cmd (WEdit * edit) add void edit_left_char_move_cmd (WEdit * edit) replace edit_cursor_move call to edit_left_char_move_cmd/edit_right_char_move_cmd in edit_execute_cmd (on key press LEFT/RIGHT) --- edit/edit.c | 97 +++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/edit/edit.c b/edit/edit.c index cc315d28a..21876eb35 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -1283,16 +1283,7 @@ edit_move_backward_lots (WEdit *edit, long increment) void edit_cursor_move (WEdit * edit, long increment) { /* this is the same as a combination of two of the above routines, with only one push onto the undo stack */ - int c = 0; - long curs1 = edit->curs1; - long curs2 = edit->curs2; - int cw = 1; - int char_step = 0; - int i; - - /* one char move*/ - if ( increment == -1 || increment == 1) - char_step = 1; + int c; #ifdef FAST_MOVE_CURSOR if (increment < -256) { @@ -1309,27 +1300,17 @@ void edit_cursor_move (WEdit * edit, long increment) edit_push_action (edit, CURS_RIGHT); - cw = 1; - if ( edit->utf8 && char_step ) { - edit_get_prev_utf (edit, curs1, &cw); - if ( cw < 1 ) - cw = 1; + c = edit_get_byte (edit, edit->curs1 - 1); + if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE)) + edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE); + edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c; + edit->curs2++; + c = edit->buffers1[(edit->curs1 - 1) >> S_EDIT_BUF_SIZE][(edit->curs1 - 1) & M_EDIT_BUF_SIZE]; + if (!((edit->curs1 - 1) & M_EDIT_BUF_SIZE)) { + g_free (edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE]); + edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = NULL; } - for ( i = 1; i<= cw; i++ ) { - c = edit_get_byte (edit, curs1 - 1); - if (!((curs2 + 1) & M_EDIT_BUF_SIZE)) - edit->buffers2[(curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE); - edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (curs2 & M_EDIT_BUF_SIZE) - 1] = c; - curs2++; - c = edit->buffers1[(curs1 - 1) >> S_EDIT_BUF_SIZE][(curs1 - 1) & M_EDIT_BUF_SIZE]; - if (!((curs1 - 1) & M_EDIT_BUF_SIZE)) { - g_free (edit->buffers1[curs1 >> S_EDIT_BUF_SIZE]); - edit->buffers1[curs1 >> S_EDIT_BUF_SIZE] = NULL; - } - curs1--; - } - edit->curs1 = curs1; - edit->curs2 = curs2; + edit->curs1--; if (c == '\n') { edit->curs_line--; edit->force |= REDRAW_LINE_BELOW; @@ -1343,27 +1324,17 @@ void edit_cursor_move (WEdit * edit, long increment) edit_push_action (edit, CURS_LEFT); - cw = 1; - if ( edit->utf8 && char_step ) { - edit_get_utf (edit, curs1, &cw); - if ( cw < 1 ) - cw = 1; + c = edit_get_byte (edit, edit->curs1); + if (!(edit->curs1 & M_EDIT_BUF_SIZE)) + edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE); + edit->buffers1[edit->curs1 >> S_EDIT_BUF_SIZE][edit->curs1 & M_EDIT_BUF_SIZE] = c; + edit->curs1++; + c = edit->buffers2[(edit->curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - ((edit->curs2 - 1) & M_EDIT_BUF_SIZE) - 1]; + if (!(edit->curs2 & M_EDIT_BUF_SIZE)) { + g_free (edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE]); + edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = 0; } - for ( i = 1; i<= cw; i++ ) { - c = edit_get_byte (edit, curs1); - if (!(curs1 & M_EDIT_BUF_SIZE)) - edit->buffers1[curs1 >> S_EDIT_BUF_SIZE] = g_malloc (EDIT_BUF_SIZE); - edit->buffers1[curs1 >> S_EDIT_BUF_SIZE][curs1 & M_EDIT_BUF_SIZE] = c; - curs1++; - c = edit->buffers2[(curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - ((curs2 - 1) & M_EDIT_BUF_SIZE) - 1]; - if (!(curs2 & M_EDIT_BUF_SIZE)) { - g_free (edit->buffers2[curs2 >> S_EDIT_BUF_SIZE]); - edit->buffers2[curs2 >> S_EDIT_BUF_SIZE] = 0; - } - curs2--; - } - edit->curs1 = curs1; - edit->curs2 = curs2; + edit->curs2--; if (c == '\n') { edit->curs_line++; edit->force |= REDRAW_LINE_ABOVE; @@ -1958,6 +1929,28 @@ static void edit_right_word_move_cmd (WEdit * edit) edit->force |= REDRAW_PAGE; } +static void edit_right_char_move_cmd (WEdit * edit) +{ + int cw = 1; + if ( edit->utf8 ) { + edit_get_utf (edit, edit->curs1, &cw); + if ( cw < 1 ) + cw = 1; + } + edit_cursor_move (edit, cw); +} + +static void edit_left_char_move_cmd (WEdit * edit) +{ + int cw = 1; + if ( edit->utf8 ) { + edit_get_prev_utf (edit, edit->curs1, &cw); + if ( cw < 1 ) + cw = 1; + } + edit_cursor_move (edit, -cw); +} + static void edit_right_delete_word (WEdit * edit) { @@ -2572,7 +2565,7 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) break; } } - edit_cursor_move (edit, -1); + edit_left_char_move_cmd (edit); break; case CK_Right: case CK_Right_Highlight: @@ -2583,7 +2576,7 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) break; } } - edit_cursor_move (edit, 1); + edit_right_char_move_cmd (edit); break; case CK_Begin_Page: case CK_Begin_Page_Highlight: From 5e5df489510d93ab7e4160192deefca02e183e81 Mon Sep 17 00:00:00 2001 From: Ilia Maslakov Date: Wed, 29 Apr 2009 07:35:00 +0000 Subject: [PATCH 2/2] fix: vertical insetrion UNDO on UTF-8 text. --- edit/edit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edit/edit.c b/edit/edit.c index 21876eb35..715c8891c 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -1140,7 +1140,7 @@ edit_backspace (WEdit * edit, const int byte_delete) edit->last_get_rule -= (edit->last_get_rule >= edit->curs1); cw = 1; - if ( edit->utf8 ) { + if ( edit->utf8 && byte_delete == 0 ) { edit_get_prev_utf (edit, edit->curs1, &cw); if ( cw < 1 ) cw = 1;