From 60fe43d932b835e37d3c6f356b50e0beb287ec56 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 18 Feb 2013 13:30:02 +0400 Subject: [PATCH] (edit_cursor_move): refactoring using editor buffer API. Signed-off-by: Andrew Borodin --- src/editor/edit.c | 48 ++++++++++------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/src/editor/edit.c b/src/editor/edit.c index c4d231d33..24d31f5c8 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -2668,63 +2668,35 @@ edit_backspace (WEdit * edit, gboolean byte_delete) void edit_cursor_move (WEdit * edit, off_t increment) { - /* this is the same as a combination of two of the above routines, with only one push onto the undo stack */ - int c; - if (increment < 0) { - for (; increment < 0; increment++) + for (; increment < 0 && edit->buffer.curs1 != 0; increment++) { - if (edit->buffer.curs1 == 0) - return; + int c; edit_push_undo_action (edit, CURS_RIGHT); - c = edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 - 1); - if (!((edit->buffer.curs2 + 1) & M_EDIT_BUF_SIZE)) - edit->buffer.buffers2[(edit->buffer.curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); - edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - - (edit->buffer.curs2 & M_EDIT_BUF_SIZE) - 1] = c; - edit->buffer.curs2++; - c = edit->buffer.buffers1[(edit->buffer.curs1 - 1) >> S_EDIT_BUF_SIZE][(edit->buffer.curs1 - - 1) & M_EDIT_BUF_SIZE]; - if (!((edit->buffer.curs1 - 1) & M_EDIT_BUF_SIZE)) - { - g_free (edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE]); - edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = NULL; - } - edit->buffer.curs1--; + c = edit_buffer_get_previous_byte (&edit->buffer); + edit_buffer_insert_ahead (&edit->buffer, c); + c = edit_buffer_backspace (&edit->buffer); if (c == '\n') { edit->curs_line--; edit->force |= REDRAW_LINE_BELOW; } } - } else { - for (; increment > 0; increment--) + for (; increment > 0 && edit->buffer.curs2 != 0; increment--) { - if (edit->buffer.curs2 == 0) - return; + int c; edit_push_undo_action (edit, CURS_LEFT); - c = edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1); - if (!(edit->buffer.curs1 & M_EDIT_BUF_SIZE)) - edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE); - edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE][edit->buffer.curs1 & M_EDIT_BUF_SIZE] = c; - edit->buffer.curs1++; - c = edit->buffer.buffers2[(edit->buffer.curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - - ((edit->buffer.curs2 - - 1) & M_EDIT_BUF_SIZE) - 1]; - if (!(edit->buffer.curs2 & M_EDIT_BUF_SIZE)) - { - g_free (edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE]); - edit->buffer.buffers2[edit->buffer.curs2 >> S_EDIT_BUF_SIZE] = 0; - } - edit->buffer.curs2--; + c = edit_buffer_get_current_byte (&edit->buffer); + edit_buffer_insert (&edit->buffer, c); + c = edit_buffer_delete (&edit->buffer); if (c == '\n') { edit->curs_line++;