New editor buffer API to delete character at cursor position.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2013-02-18 12:13:05 +04:00
parent e335bba08c
commit ed8c80f48d
3 changed files with 69 additions and 17 deletions

View File

@ -2577,17 +2577,9 @@ edit_delete (WEdit * edit, gboolean byte_delete)
if (edit->last_get_rule > edit->buffer.curs1)
edit->last_get_rule--;
p = edit->buffer.buffers2[(edit->buffer.curs2 - 1) >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE -
((edit->buffer.curs2 -
1) & M_EDIT_BUF_SIZE) - 1];
p = edit_buffer_delete (&edit->buffer);
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] = NULL;
}
edit->last_byte--;
edit->buffer.curs2--;
edit_push_undo_action (edit, p + 256);
}
@ -2646,15 +2638,9 @@ edit_backspace (WEdit * edit, gboolean byte_delete)
if (edit->last_get_rule >= edit->buffer.curs1)
edit->last_get_rule--;
p = *(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) == 0)
{
g_free (edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE]);
edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = NULL;
}
p = edit_buffer_backspace (&edit->buffer);
edit->last_byte--;
edit->buffer.curs1--;
edit_push_undo_action (edit, p);
}
edit_modification (edit);

View File

@ -353,6 +353,70 @@ edit_buffer_insert_ahead (edit_buffer_t * buf, int c)
buf->curs2++;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Basic low level single character buffer alterations and movements at the cursor: delete character
* at the cursor position.
*
* @param buf pointer to editor buffer
* @param c character to insert
*/
int
edit_buffer_delete (edit_buffer_t * buf)
{
unsigned char c;
off_t prev;
off_t i;
prev = buf->curs2 - 1;
i = prev & M_EDIT_BUF_SIZE;
c = buf->buffers2[prev >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - 1 - i];
if ((buf->curs2 & M_EDIT_BUF_SIZE) == 0)
{
g_free (buf->buffers2[buf->curs2 >> S_EDIT_BUF_SIZE]);
buf->buffers2[buf->curs2 >> S_EDIT_BUF_SIZE] = NULL;
}
buf->curs2 = prev;
return c;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Basic low level single character buffer alterations and movements at the cursor: delete character
* before the cursor position and move left.
*
* @param buf pointer to editor buffer
* @param c character to insert
*/
int
edit_buffer_backspace (edit_buffer_t * buf)
{
unsigned char c;
off_t prev;
off_t i;
prev = buf->curs1 - 1;
i = prev & M_EDIT_BUF_SIZE;
c = buf->buffers1[prev >> S_EDIT_BUF_SIZE][i];
if (i == 0)
{
g_free (buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE]);
buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE] = NULL;
}
buf->curs1 = prev;
return c;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Load file into editor buffer

View File

@ -60,6 +60,8 @@ int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *
void edit_buffer_insert (edit_buffer_t * buf, int c);
void edit_buffer_insert_ahead (edit_buffer_t * buf, int c);
int edit_buffer_delete (edit_buffer_t * buf);
int edit_buffer_backspace (edit_buffer_t * buf);
off_t edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size);
off_t edit_buffer_write_file (edit_buffer_t * buf, int fd);