New editor buffer API to insert character at cursor position.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
706257a47d
Коммит
e335bba08c
@ -2441,7 +2441,6 @@ edit_push_redo_action (WEdit * edit, long c)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
Basic low level single character buffer alterations and movements at the cursor.
|
||||
Returns char passed over, inserted or removed.
|
||||
*/
|
||||
|
||||
void
|
||||
@ -2479,23 +2478,14 @@ edit_insert (WEdit * edit, int c)
|
||||
else
|
||||
edit_push_undo_action (edit, BACKSPACE_BR);
|
||||
/* update markers */
|
||||
edit->mark1 += (edit->mark1 > edit->buffer.curs1);
|
||||
edit->mark2 += (edit->mark2 > edit->buffer.curs1);
|
||||
edit->last_get_rule += (edit->last_get_rule > edit->buffer.curs1);
|
||||
edit->mark1 += (edit->mark1 > edit->buffer.curs1) ? 1 : 0;
|
||||
edit->mark2 += (edit->mark2 > edit->buffer.curs1) ? 1 : 0;
|
||||
edit->last_get_rule += (edit->last_get_rule > edit->buffer.curs1) ? 1 : 0;
|
||||
|
||||
/* add a new buffer if we've reached the end of the last one */
|
||||
if (!(edit->buffer.curs1 & M_EDIT_BUF_SIZE))
|
||||
edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
|
||||
|
||||
/* perform the insertion */
|
||||
edit->buffer.buffers1[edit->buffer.curs1 >> S_EDIT_BUF_SIZE][edit->buffer.curs1 & M_EDIT_BUF_SIZE]
|
||||
= (unsigned char) c;
|
||||
edit_buffer_insert (&edit->buffer, c);
|
||||
|
||||
/* update file length */
|
||||
edit->last_byte++;
|
||||
|
||||
/* update cursor position */
|
||||
edit->buffer.curs1++;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -2526,17 +2516,13 @@ edit_insert_ahead (WEdit * edit, int c)
|
||||
else
|
||||
edit_push_undo_action (edit, DELCHAR_BR);
|
||||
|
||||
edit->mark1 += (edit->mark1 >= edit->buffer.curs1);
|
||||
edit->mark2 += (edit->mark2 >= edit->buffer.curs1);
|
||||
edit->last_get_rule += (edit->last_get_rule >= edit->buffer.curs1);
|
||||
edit->mark1 += (edit->mark1 >= edit->buffer.curs1) ? 1 : 0;
|
||||
edit->mark2 += (edit->mark2 >= edit->buffer.curs1) ? 1 : 0;
|
||||
edit->last_get_rule += (edit->last_get_rule >= edit->buffer.curs1) ? 1 : 0;
|
||||
|
||||
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_insert_ahead (&edit->buffer, c);
|
||||
|
||||
edit->last_byte++;
|
||||
edit->buffer.curs2++;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -299,6 +299,60 @@ edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char
|
||||
}
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Basic low level single character buffer alterations and movements at the cursor: insert character
|
||||
* at the cursor position and move right.
|
||||
*
|
||||
* @param buf pointer to editor buffer
|
||||
* @param c character to insert
|
||||
*/
|
||||
|
||||
void
|
||||
edit_buffer_insert (edit_buffer_t * buf, int c)
|
||||
{
|
||||
off_t i;
|
||||
|
||||
i = buf->curs1 & M_EDIT_BUF_SIZE;
|
||||
|
||||
/* add a new buffer if we've reached the end of the last one */
|
||||
if (i == 0)
|
||||
buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
|
||||
|
||||
/* perform the insertion */
|
||||
buf->buffers1[buf->curs1 >> S_EDIT_BUF_SIZE][i] = (unsigned char) c;
|
||||
|
||||
/* update cursor position */
|
||||
buf->curs1++;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Basic low level single character buffer alterations and movements at the cursor: insert character
|
||||
* at the cursor position and move left.
|
||||
*
|
||||
* @param buf pointer to editor buffer
|
||||
* @param c character to insert
|
||||
*/
|
||||
|
||||
void
|
||||
edit_buffer_insert_ahead (edit_buffer_t * buf, int c)
|
||||
{
|
||||
off_t i;
|
||||
|
||||
i = buf->curs2 & M_EDIT_BUF_SIZE;
|
||||
|
||||
/* add a new buffer if we've reached the end of the last one */
|
||||
if (((buf->curs2 + 1) & M_EDIT_BUF_SIZE) == 0)
|
||||
buf->buffers2[(buf->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
|
||||
|
||||
/* perform the insertion */
|
||||
buf->buffers2[buf->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - 1 - i] = (unsigned char) c;
|
||||
|
||||
/* update cursor position */
|
||||
buf->curs2++;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Load file into editor buffer
|
||||
|
@ -58,6 +58,9 @@ int edit_buffer_get_utf (const edit_buffer_t * buf, off_t byte_index, int *char_
|
||||
int edit_buffer_get_prev_utf (const edit_buffer_t * buf, off_t byte_index, int *char_width);
|
||||
#endif
|
||||
|
||||
void edit_buffer_insert (edit_buffer_t * buf, int c);
|
||||
void edit_buffer_insert_ahead (edit_buffer_t * buf, int c);
|
||||
|
||||
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);
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user