forked from PsychoticNinja/irssi
Merge pull request #353 from toddpratt/master
Allow for prepending to the cutbuffer in addition to replacing it.
This commit is contained in:
commit
dc03baa0d3
@ -562,7 +562,7 @@ char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, int update_cutbuffer)
|
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, CUTBUFFER_UPDATE_OP update_cutbuffer)
|
||||||
{
|
{
|
||||||
int newpos, size = 0;
|
int newpos, size = 0;
|
||||||
|
|
||||||
@ -573,7 +573,7 @@ void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, int update_cutbuffer)
|
|||||||
gui_entry_erase(entry, size, update_cutbuffer);
|
gui_entry_erase(entry, size, update_cutbuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer)
|
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_cutbuffer)
|
||||||
{
|
{
|
||||||
size_t w = 0;
|
size_t w = 0;
|
||||||
|
|
||||||
@ -582,7 +582,26 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer)
|
|||||||
if (size == 0 || entry->pos < size)
|
if (size == 0 || entry->pos < size)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (update_cutbuffer) {
|
switch (update_cutbuffer) {
|
||||||
|
case CUTBUFFER_UPDATE_PREPEND:
|
||||||
|
if (entry->cutbuffer_len) {
|
||||||
|
int cutbuffer_new_size = entry->cutbuffer_len + size;
|
||||||
|
unichar *tmpcutbuffer = entry->cutbuffer;
|
||||||
|
entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1);
|
||||||
|
|
||||||
|
memcpy(entry->cutbuffer, entry->text + entry->pos - size,
|
||||||
|
size * sizeof(unichar));
|
||||||
|
memcpy(entry->cutbuffer + size, tmpcutbuffer,
|
||||||
|
entry->cutbuffer_len * sizeof(unichar));
|
||||||
|
|
||||||
|
entry->cutbuffer_len = cutbuffer_new_size;
|
||||||
|
entry->cutbuffer[cutbuffer_new_size] = '\0';
|
||||||
|
|
||||||
|
g_free(tmpcutbuffer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* fall through to REPLACE if cutbuffer_len was 0 */
|
||||||
|
case CUTBUFFER_UPDATE_REPLACE:
|
||||||
/* put erased text to cutbuffer */
|
/* put erased text to cutbuffer */
|
||||||
if (entry->cutbuffer_len < size) {
|
if (entry->cutbuffer_len < size) {
|
||||||
g_free(entry->cutbuffer);
|
g_free(entry->cutbuffer);
|
||||||
@ -593,6 +612,9 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer)
|
|||||||
entry->cutbuffer[size] = '\0';
|
entry->cutbuffer[size] = '\0';
|
||||||
memcpy(entry->cutbuffer, entry->text + entry->pos - size,
|
memcpy(entry->cutbuffer, entry->text + entry->pos - size,
|
||||||
size * sizeof(unichar));
|
size * sizeof(unichar));
|
||||||
|
break;
|
||||||
|
case CUTBUFFER_UPDATE_NOOP:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry->utf8)
|
if (entry->utf8)
|
||||||
@ -629,7 +651,7 @@ void gui_entry_erase_cell(GUI_ENTRY_REC *entry)
|
|||||||
gui_entry_draw(entry);
|
gui_entry_draw(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space)
|
void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space, CUTBUFFER_UPDATE_OP cutbuffer_op)
|
||||||
{
|
{
|
||||||
int to;
|
int to;
|
||||||
|
|
||||||
@ -652,7 +674,7 @@ void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space)
|
|||||||
}
|
}
|
||||||
if (to > 0) to++;
|
if (to > 0) to++;
|
||||||
|
|
||||||
gui_entry_erase(entry, entry->pos-to, TRUE);
|
gui_entry_erase(entry, entry->pos-to, CUTBUFFER_UPDATE_REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space)
|
void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space)
|
||||||
@ -678,7 +700,7 @@ void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space)
|
|||||||
|
|
||||||
size = to-entry->pos;
|
size = to-entry->pos;
|
||||||
entry->pos = to;
|
entry->pos = to;
|
||||||
gui_entry_erase(entry, size, TRUE);
|
gui_entry_erase(entry, size, CUTBUFFER_UPDATE_REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_entry_transpose_chars(GUI_ENTRY_REC *entry)
|
void gui_entry_transpose_chars(GUI_ENTRY_REC *entry)
|
||||||
|
@ -20,6 +20,12 @@ typedef struct {
|
|||||||
unsigned int utf8:1;
|
unsigned int utf8:1;
|
||||||
} GUI_ENTRY_REC;
|
} GUI_ENTRY_REC;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CUTBUFFER_UPDATE_NOOP,
|
||||||
|
CUTBUFFER_UPDATE_REPLACE,
|
||||||
|
CUTBUFFER_UPDATE_PREPEND
|
||||||
|
} CUTBUFFER_UPDATE_OP;
|
||||||
|
|
||||||
extern GUI_ENTRY_REC *active_entry;
|
extern GUI_ENTRY_REC *active_entry;
|
||||||
|
|
||||||
GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width, int utf8);
|
GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width, int utf8);
|
||||||
@ -40,10 +46,10 @@ void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str);
|
|||||||
void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr);
|
void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr);
|
||||||
|
|
||||||
char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry);
|
char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry);
|
||||||
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, int update_cutbuffer);
|
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, CUTBUFFER_UPDATE_OP update_cutbuffer);
|
||||||
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer);
|
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_cutbuffer);
|
||||||
void gui_entry_erase_cell(GUI_ENTRY_REC *entry);
|
void gui_entry_erase_cell(GUI_ENTRY_REC *entry);
|
||||||
void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space);
|
void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space, CUTBUFFER_UPDATE_OP cutbuffer_op);
|
||||||
void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space);
|
void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space);
|
||||||
|
|
||||||
void gui_entry_transpose_chars(GUI_ENTRY_REC *entry);
|
void gui_entry_transpose_chars(GUI_ENTRY_REC *entry);
|
||||||
@ -60,4 +66,5 @@ void gui_entry_move_words(GUI_ENTRY_REC *entry, int count, int to_space);
|
|||||||
|
|
||||||
void gui_entry_redraw(GUI_ENTRY_REC *entry);
|
void gui_entry_redraw(GUI_ENTRY_REC *entry);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -547,7 +547,7 @@ static void key_forward_to_space(void)
|
|||||||
static void key_erase_line(void)
|
static void key_erase_line(void)
|
||||||
{
|
{
|
||||||
gui_entry_set_pos(active_entry, active_entry->text_len);
|
gui_entry_set_pos(active_entry, active_entry->text_len);
|
||||||
gui_entry_erase(active_entry, active_entry->text_len, TRUE);
|
gui_entry_erase(active_entry, active_entry->text_len, CUTBUFFER_UPDATE_REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_erase_to_beg_of_line(void)
|
static void key_erase_to_beg_of_line(void)
|
||||||
@ -555,7 +555,7 @@ static void key_erase_to_beg_of_line(void)
|
|||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
pos = gui_entry_get_pos(active_entry);
|
pos = gui_entry_get_pos(active_entry);
|
||||||
gui_entry_erase(active_entry, pos, TRUE);
|
gui_entry_erase(active_entry, pos, CUTBUFFER_UPDATE_REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_erase_to_end_of_line(void)
|
static void key_erase_to_end_of_line(void)
|
||||||
@ -564,7 +564,7 @@ static void key_erase_to_end_of_line(void)
|
|||||||
|
|
||||||
pos = gui_entry_get_pos(active_entry);
|
pos = gui_entry_get_pos(active_entry);
|
||||||
gui_entry_set_pos(active_entry, active_entry->text_len);
|
gui_entry_set_pos(active_entry, active_entry->text_len);
|
||||||
gui_entry_erase(active_entry, active_entry->text_len - pos, TRUE);
|
gui_entry_erase(active_entry, active_entry->text_len - pos, CUTBUFFER_UPDATE_REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_yank_from_cutbuffer(void)
|
static void key_yank_from_cutbuffer(void)
|
||||||
@ -611,12 +611,12 @@ static void key_delete_character(void)
|
|||||||
|
|
||||||
static void key_backspace(void)
|
static void key_backspace(void)
|
||||||
{
|
{
|
||||||
gui_entry_erase(active_entry, 1, FALSE);
|
gui_entry_erase(active_entry, 1, CUTBUFFER_UPDATE_NOOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_delete_previous_word(void)
|
static void key_delete_previous_word(void)
|
||||||
{
|
{
|
||||||
gui_entry_erase_word(active_entry, FALSE);
|
gui_entry_erase_word(active_entry, FALSE, CUTBUFFER_UPDATE_REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_delete_next_word(void)
|
static void key_delete_next_word(void)
|
||||||
@ -626,7 +626,7 @@ static void key_delete_next_word(void)
|
|||||||
|
|
||||||
static void key_delete_to_previous_space(void)
|
static void key_delete_to_previous_space(void)
|
||||||
{
|
{
|
||||||
gui_entry_erase_word(active_entry, TRUE);
|
gui_entry_erase_word(active_entry, TRUE, CUTBUFFER_UPDATE_REPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_delete_to_next_space(void)
|
static void key_delete_to_next_space(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user