From 3c95f6aae9826c10a50c4a0f12c16fca6038410c Mon Sep 17 00:00:00 2001 From: "Todd A. Pratt" Date: Mon, 2 Nov 2015 08:00:52 -0500 Subject: Make C-w and M-backspace work right. --- src/fe-text/gui-entry.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 17a7c507..b7d58019 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -555,16 +555,31 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer) return; if (update_cutbuffer) { - /* put erased text to cutbuffer */ - if (entry->cutbuffer_len < size) { - g_free(entry->cutbuffer); - entry->cutbuffer = g_new(unichar, size+1); + if (entry->cutbuffer_len && update_cutbuffer == CUTBUFFER_PREPEND) { + 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); + } else if (update_cutbuffer) { + /* put erased text to cutbuffer */ + if (entry->cutbuffer_len < size) { + g_free(entry->cutbuffer); + entry->cutbuffer = g_new(unichar, size+1); + } + entry->cutbuffer_len = size; + entry->cutbuffer[size] = '\0'; + memcpy(entry->cutbuffer, entry->text + entry->pos - size, + size * sizeof(unichar)); } - - entry->cutbuffer_len = size; - entry->cutbuffer[size] = '\0'; - memcpy(entry->cutbuffer, entry->text + entry->pos - size, - size * sizeof(unichar)); } if (entry->utf8) @@ -601,7 +616,7 @@ void gui_entry_erase_cell(GUI_ENTRY_REC *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, int repeat) { int to; @@ -624,7 +639,8 @@ void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space) } if (to > 0) to++; - gui_entry_erase(entry, entry->pos-to, TRUE); + gui_entry_erase(entry, entry->pos-to, + repeat ? CUTBUFFER_PREPEND : TRUE); } void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space) -- cgit v1.2.3 From 1199ecc62f137eedb388b3dbd9b003cf1a8280f7 Mon Sep 17 00:00:00 2001 From: "Todd A. Pratt" Date: Fri, 13 Nov 2015 13:42:28 -0500 Subject: a facility for prepending or replacing the cutbuffer --- src/fe-text/gui-entry.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index a83bcf64..ec484cb5 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -534,7 +534,7 @@ char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry) 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; @@ -545,7 +545,7 @@ void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, int 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; @@ -554,32 +554,39 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer) if (size == 0 || entry->pos < size) return; - if (update_cutbuffer) { - if (entry->cutbuffer_len && update_cutbuffer == CUTBUFFER_PREPEND) { - int cutbuffer_new_size = entry->cutbuffer_len + size; - unichar *tmpcutbuffer = entry->cutbuffer; - entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1); + 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, + 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'; + entry->cutbuffer_len * sizeof(unichar)); + entry->cutbuffer_len = cutbuffer_new_size; + entry->cutbuffer[cutbuffer_new_size] = '\0'; - g_free(tmpcutbuffer); - } else if (update_cutbuffer) { + g_free(tmpcutbuffer); + break; + } + /* fall through to REPLACE if cutbuffer_len was 0 */ + case CUTBUFFER_UPDATE_REPLACE: /* put erased text to cutbuffer */ if (entry->cutbuffer_len < size) { g_free(entry->cutbuffer); entry->cutbuffer = g_new(unichar, size+1); } + entry->cutbuffer_len = size; entry->cutbuffer[size] = '\0'; memcpy(entry->cutbuffer, entry->text + entry->pos - size, - size * sizeof(unichar)); - } + size * sizeof(unichar)); + break; + case CUTBUFFER_UPDATE_NOOP: + break; } if (entry->utf8) @@ -616,7 +623,7 @@ void gui_entry_erase_cell(GUI_ENTRY_REC *entry) gui_entry_draw(entry); } -void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space, int repeat) +void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space, CUTBUFFER_UPDATE_OP cutbuffer_op) { int to; @@ -639,8 +646,6 @@ void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space, int repeat) } if (to > 0) to++; - gui_entry_erase(entry, entry->pos-to, - repeat ? CUTBUFFER_PREPEND : TRUE); } void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space) @@ -666,7 +671,7 @@ void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space) size = to-entry->pos; 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) -- cgit v1.2.3 From bb8c0bbf4caf87172255993ce8a86f91a8cd4208 Mon Sep 17 00:00:00 2001 From: "Todd A. Pratt" Date: Fri, 13 Nov 2015 20:33:57 -0500 Subject: fix indentation, undelete line not meant to be deleted. --- src/fe-text/gui-entry.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index ec484cb5..650995bd 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -564,8 +564,8 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ memcpy(entry->cutbuffer, entry->text + entry->pos - size, size * sizeof(unichar)); memcpy(entry->cutbuffer + size, tmpcutbuffer, + entry->cutbuffer_len * sizeof(unichar)); - entry->cutbuffer_len * sizeof(unichar)); entry->cutbuffer_len = cutbuffer_new_size; entry->cutbuffer[cutbuffer_new_size] = '\0'; @@ -646,6 +646,7 @@ void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space, CUTBUFFER_UPDATE_O } if (to > 0) to++; + gui_entry_erase(entry, entry->pos-to, TRUE); } void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space) -- cgit v1.2.3 From 15dfb27f80922f6f3b751da9e1395994c3026a62 Mon Sep 17 00:00:00 2001 From: "Todd A. Pratt" Date: Sat, 14 Nov 2015 09:07:35 -0500 Subject: use the enum name which was the original intended change --- src/fe-text/gui-entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 650995bd..176ee431 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -646,7 +646,7 @@ void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space, CUTBUFFER_UPDATE_O } 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) -- cgit v1.2.3 From 876609901a5476ab2764a8002b9c57d25dc34f20 Mon Sep 17 00:00:00 2001 From: "Todd A. Pratt" Date: Sat, 30 Jan 2016 09:34:46 -0500 Subject: add an append operation to cut buffer handling --- src/fe-text/gui-entry.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 6e13ba4e..58743ac3 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -582,25 +582,40 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ if (size == 0 || entry->pos < size) return; + if (entry->cutbuffer_len == 0) { + update_cutbuffer = CUTBUFFER_UPDATE_REPLACE; + } + int cutbuffer_new_size = entry->cutbuffer_len + size; + unichar *tmpcutbuffer = entry->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)); + case CUTBUFFER_UPDATE_APPEND: + entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1); + if (entry->cutbuffer) { + memcpy(entry->cutbuffer, tmpcutbuffer, + entry->cutbuffer_len * sizeof(unichar)); + memcpy(entry->cutbuffer + entry->cutbuffer_len * sizeof(unichar), + entry->text + entry->pos - size, size * sizeof(unichar)); + + entry->cutbuffer_len = cutbuffer_new_size; + entry->cutbuffer[cutbuffer_new_size] = '\0'; + g_free(tmpcutbuffer); + } + break; - entry->cutbuffer_len = cutbuffer_new_size; - entry->cutbuffer[cutbuffer_new_size] = '\0'; + case CUTBUFFER_UPDATE_PREPEND: + entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1); + if (entry->cutbuffer) { + 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; - g_free(tmpcutbuffer); - break; - } - /* fall through to REPLACE if cutbuffer_len was 0 */ case CUTBUFFER_UPDATE_REPLACE: /* put erased text to cutbuffer */ if (entry->cutbuffer_len < size) { @@ -613,6 +628,7 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ memcpy(entry->cutbuffer, entry->text + entry->pos - size, size * sizeof(unichar)); break; + case CUTBUFFER_UPDATE_NOOP: break; } -- cgit v1.2.3 From 966d002b55eb0b49a04833e5a51b9ab265013eab Mon Sep 17 00:00:00 2001 From: "Todd A. Pratt" Date: Sat, 30 Jan 2016 11:32:08 -0500 Subject: remove memory allocation check, spaces to tabs --- src/fe-text/gui-entry.c | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 58743ac3..78b9166d 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -589,32 +589,28 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ unichar *tmpcutbuffer = entry->cutbuffer; switch (update_cutbuffer) { case CUTBUFFER_UPDATE_APPEND: - entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1); - if (entry->cutbuffer) { - memcpy(entry->cutbuffer, tmpcutbuffer, - entry->cutbuffer_len * sizeof(unichar)); - memcpy(entry->cutbuffer + entry->cutbuffer_len * sizeof(unichar), - entry->text + entry->pos - size, size * sizeof(unichar)); - - entry->cutbuffer_len = cutbuffer_new_size; - entry->cutbuffer[cutbuffer_new_size] = '\0'; - g_free(tmpcutbuffer); - } - break; + entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1); + memcpy(entry->cutbuffer, tmpcutbuffer, + entry->cutbuffer_len * sizeof(unichar)); + memcpy(entry->cutbuffer + entry->cutbuffer_len * sizeof(unichar), + entry->text + entry->pos - size, size * sizeof(unichar)); + + entry->cutbuffer_len = cutbuffer_new_size; + entry->cutbuffer[cutbuffer_new_size] = '\0'; + g_free(tmpcutbuffer); + break; case CUTBUFFER_UPDATE_PREPEND: - entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1); - if (entry->cutbuffer) { - 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; + 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; case CUTBUFFER_UPDATE_REPLACE: /* put erased text to cutbuffer */ -- cgit v1.2.3 From 8723c0fb339dcf58c164fbc741122f9c3657ddea Mon Sep 17 00:00:00 2001 From: "Todd A. Pratt" Date: Wed, 10 Feb 2016 09:47:10 -0500 Subject: fix whitespace --- src/fe-text/gui-entry.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 78b9166d..27778b2b 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -582,11 +582,11 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ if (size == 0 || entry->pos < size) return; - if (entry->cutbuffer_len == 0) { - update_cutbuffer = CUTBUFFER_UPDATE_REPLACE; - } - int cutbuffer_new_size = entry->cutbuffer_len + size; - unichar *tmpcutbuffer = entry->cutbuffer; + if (entry->cutbuffer_len == 0) { + update_cutbuffer = CUTBUFFER_UPDATE_REPLACE; + } + int cutbuffer_new_size = entry->cutbuffer_len + size; + unichar *tmpcutbuffer = entry->cutbuffer; switch (update_cutbuffer) { case CUTBUFFER_UPDATE_APPEND: entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1); @@ -621,8 +621,7 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ entry->cutbuffer_len = size; entry->cutbuffer[size] = '\0'; - memcpy(entry->cutbuffer, entry->text + entry->pos - size, - size * sizeof(unichar)); + memcpy(entry->cutbuffer, entry->text + entry->pos - size, size * sizeof(unichar)); break; case CUTBUFFER_UPDATE_NOOP: -- cgit v1.2.3 From 117c890d98d54fdee85a56f851acd6f4b3bd3be3 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Tue, 22 Mar 2016 14:43:31 +0100 Subject: cutbuffer: do not unconditionally use replace when noop was requested --- src/fe-text/gui-entry.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 27778b2b..f275c235 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -582,7 +582,8 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ if (size == 0 || entry->pos < size) return; - if (entry->cutbuffer_len == 0) { + if (update_cutbuffer != CUTBUFFER_UPDATE_NOOP + && entry->cutbuffer_len == 0) { update_cutbuffer = CUTBUFFER_UPDATE_REPLACE; } int cutbuffer_new_size = entry->cutbuffer_len + size; -- cgit v1.2.3 From aec2466e36ec32e97ec2eb8e1279e27a3d0fe0cb Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Mon, 21 Mar 2016 09:14:01 +0100 Subject: Improve cutbuffer handling * Adds two new keys which you can bind in /bind: yank_next_cutbuffer: Revert to the previous last deleted text append_next_kill: Append next deletion * Consecutive kills are now appended to the current cutbuffer --- src/fe-text/gui-entry.c | 179 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 127 insertions(+), 52 deletions(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index f275c235..63dda34e 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -32,6 +32,8 @@ #undef i_tolower #undef i_isalnum +#define KILL_RING_MAX 10 + static unichar i_toupper(unichar c) { if (term_type == TERM_TYPE_UTF8) @@ -82,11 +84,22 @@ GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width, int utf8) void gui_entry_destroy(GUI_ENTRY_REC *entry) { + GSList *tmp; + g_return_if_fail(entry != NULL); if (active_entry == entry) gui_entry_set_active(NULL); + for (tmp = entry->kill_ring; tmp != NULL; tmp = tmp->next) { + GUI_ENTRY_CUTBUFFER_REC *rec = tmp->data; + if (rec != NULL) { + g_free(rec->cutbuffer); + g_free(rec); + } + } + g_slist_free(entry->kill_ring); + g_free(entry->text); g_free(entry->prompt); g_free(entry); @@ -546,22 +559,42 @@ char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry) g_return_val_if_fail(entry != NULL, NULL); - if (entry->cutbuffer == NULL) + if (entry->kill_ring == NULL || entry->kill_ring->data == NULL) + return NULL; + + GUI_ENTRY_CUTBUFFER_REC *tmp = entry->kill_ring->data; + + if (tmp->cutbuffer == NULL) return NULL; if (entry->utf8) - buf = g_ucs4_to_utf8(entry->cutbuffer, -1, NULL, NULL, NULL); + buf = g_ucs4_to_utf8(tmp->cutbuffer, -1, NULL, NULL, NULL); else { - buf = g_malloc(entry->cutbuffer_len*6 + 1); + buf = g_malloc(tmp->cutbuffer_len*6 + 1); if (term_type == TERM_TYPE_BIG5) - unichars_to_big5(entry->cutbuffer, buf); + unichars_to_big5(tmp->cutbuffer, buf); else - for (i = 0; i <= entry->cutbuffer_len; i++) - buf[i] = entry->cutbuffer[i]; + for (i = 0; i <= tmp->cutbuffer_len; i++) + buf[i] = tmp->cutbuffer[i]; } return buf; } +char *gui_entry_get_next_cutbuffer(GUI_ENTRY_REC *entry) +{ + g_return_val_if_fail(entry != NULL, NULL); + + if (entry->kill_ring == NULL) + return NULL; + + GUI_ENTRY_CUTBUFFER_REC *tmp = entry->kill_ring->data; + + entry->kill_ring = g_slist_remove(entry->kill_ring, tmp); + entry->kill_ring = g_slist_append(entry->kill_ring, tmp); + + return gui_entry_get_cutbuffer(entry); +} + void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, CUTBUFFER_UPDATE_OP update_cutbuffer) { int newpos, size = 0; @@ -573,6 +606,40 @@ void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, CUTBUFFER_UPDATE_OP updat gui_entry_erase(entry, size, update_cutbuffer); } +static GUI_ENTRY_CUTBUFFER_REC *get_cutbuffer_rec(GUI_ENTRY_REC *entry, CUTBUFFER_UPDATE_OP update_cutbuffer) +{ + GUI_ENTRY_CUTBUFFER_REC *tmp = NULL; + + g_return_val_if_fail(entry != NULL, NULL); + + if (entry->kill_ring == NULL) { + /* no kill ring exists */ + entry->kill_ring = g_slist_prepend(entry->kill_ring, (void *)NULL); + } else { + tmp = entry->kill_ring->data; + + if (tmp != NULL && tmp->cutbuffer_len > 0 + && (!entry->previous_append_next_kill + || update_cutbuffer == CUTBUFFER_UPDATE_REPLACE)) { + /* a cutbuffer exists and should be replaced */ + entry->kill_ring = g_slist_prepend(entry->kill_ring, (void *)NULL); + } + } + + if (g_slist_length(entry->kill_ring) > KILL_RING_MAX) { + GUI_ENTRY_CUTBUFFER_REC *rec = g_slist_last(entry->kill_ring)->data; + entry->kill_ring = g_slist_remove(entry->kill_ring, rec); + if (rec != NULL) g_free(rec->cutbuffer); + g_free(rec); + } + + if (entry->kill_ring->data == NULL) { + entry->kill_ring->data = g_new0(GUI_ENTRY_CUTBUFFER_REC, 1); + } + + return entry->kill_ring->data; +} + void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_cutbuffer) { size_t w = 0; @@ -582,51 +649,59 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ if (size == 0 || entry->pos < size) return; - if (update_cutbuffer != CUTBUFFER_UPDATE_NOOP - && entry->cutbuffer_len == 0) { - update_cutbuffer = CUTBUFFER_UPDATE_REPLACE; - } - int cutbuffer_new_size = entry->cutbuffer_len + size; - unichar *tmpcutbuffer = entry->cutbuffer; - switch (update_cutbuffer) { - case CUTBUFFER_UPDATE_APPEND: - entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1); - memcpy(entry->cutbuffer, tmpcutbuffer, - entry->cutbuffer_len * sizeof(unichar)); - memcpy(entry->cutbuffer + entry->cutbuffer_len * sizeof(unichar), - entry->text + entry->pos - size, size * sizeof(unichar)); - - entry->cutbuffer_len = cutbuffer_new_size; - entry->cutbuffer[cutbuffer_new_size] = '\0'; - g_free(tmpcutbuffer); - break; - - case CUTBUFFER_UPDATE_PREPEND: - 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; - - case CUTBUFFER_UPDATE_REPLACE: - /* put erased text to cutbuffer */ - if (entry->cutbuffer_len < size) { - g_free(entry->cutbuffer); - entry->cutbuffer = g_new(unichar, size+1); - } + if (update_cutbuffer != CUTBUFFER_UPDATE_NOOP) { + int cutbuffer_new_size; + unichar *tmpcutbuffer; + GUI_ENTRY_CUTBUFFER_REC *tmp = get_cutbuffer_rec(entry, update_cutbuffer); - entry->cutbuffer_len = size; - entry->cutbuffer[size] = '\0'; - memcpy(entry->cutbuffer, entry->text + entry->pos - size, size * sizeof(unichar)); - break; + if (tmp->cutbuffer_len == 0) { + update_cutbuffer = CUTBUFFER_UPDATE_REPLACE; + } - case CUTBUFFER_UPDATE_NOOP: - break; + cutbuffer_new_size = tmp->cutbuffer_len + size; + tmpcutbuffer = tmp->cutbuffer; + entry->append_next_kill = TRUE; + switch (update_cutbuffer) { + case CUTBUFFER_UPDATE_APPEND: + tmp->cutbuffer = g_new(unichar, cutbuffer_new_size+1); + memcpy(tmp->cutbuffer, tmpcutbuffer, + tmp->cutbuffer_len * sizeof(unichar)); + memcpy(tmp->cutbuffer + tmp->cutbuffer_len * sizeof(unichar), + entry->text + entry->pos - size, size * sizeof(unichar)); + + tmp->cutbuffer_len = cutbuffer_new_size; + tmp->cutbuffer[cutbuffer_new_size] = '\0'; + g_free(tmpcutbuffer); + break; + + case CUTBUFFER_UPDATE_PREPEND: + tmp->cutbuffer = g_new(unichar, cutbuffer_new_size+1); + memcpy(tmp->cutbuffer, entry->text + entry->pos - size, + size * sizeof(unichar)); + memcpy(tmp->cutbuffer + size, tmpcutbuffer, + tmp->cutbuffer_len * sizeof(unichar)); + + tmp->cutbuffer_len = cutbuffer_new_size; + tmp->cutbuffer[cutbuffer_new_size] = '\0'; + g_free(tmpcutbuffer); + break; + + case CUTBUFFER_UPDATE_REPLACE: + /* put erased text to cutbuffer */ + if (tmp->cutbuffer_len < size) { + g_free(tmp->cutbuffer); + tmp->cutbuffer = g_new(unichar, size+1); + } + + tmp->cutbuffer_len = size; + tmp->cutbuffer[size] = '\0'; + memcpy(tmp->cutbuffer, entry->text + entry->pos - size, size * sizeof(unichar)); + break; + + case CUTBUFFER_UPDATE_NOOP: + /* cannot happen, handled in "if" */ + break; + } } if (entry->utf8) @@ -686,10 +761,10 @@ void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space, CUTBUFFER_UPDATE_O } if (to > 0) to++; - gui_entry_erase(entry, entry->pos-to, CUTBUFFER_UPDATE_REPLACE); + gui_entry_erase(entry, entry->pos-to, 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, CUTBUFFER_UPDATE_OP cutbuffer_op) { int to, size; @@ -712,7 +787,7 @@ void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space) size = to-entry->pos; entry->pos = to; - gui_entry_erase(entry, size, CUTBUFFER_UPDATE_REPLACE); + gui_entry_erase(entry, size, cutbuffer_op); } void gui_entry_transpose_chars(GUI_ENTRY_REC *entry) -- cgit v1.2.3 From 47e792da05f79c624a190fd5780e07f171fd7bd1 Mon Sep 17 00:00:00 2001 From: pisculichi Date: Mon, 2 May 2016 16:01:48 +0000 Subject: Fix some ANSI C issues. --- src/fe-text/gui-entry.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 63dda34e..31fe0e1e 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -554,6 +554,7 @@ void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr) char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry) { + GUI_ENTRY_CUTBUFFER_REC *tmp; char *buf; int i; @@ -562,7 +563,7 @@ char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry) if (entry->kill_ring == NULL || entry->kill_ring->data == NULL) return NULL; - GUI_ENTRY_CUTBUFFER_REC *tmp = entry->kill_ring->data; + tmp = entry->kill_ring->data; if (tmp->cutbuffer == NULL) return NULL; @@ -582,12 +583,14 @@ char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry) char *gui_entry_get_next_cutbuffer(GUI_ENTRY_REC *entry) { + GUI_ENTRY_CUTBUFFER_REC *tmp; + g_return_val_if_fail(entry != NULL, NULL); if (entry->kill_ring == NULL) return NULL; - GUI_ENTRY_CUTBUFFER_REC *tmp = entry->kill_ring->data; + tmp = entry->kill_ring->data; entry->kill_ring = g_slist_remove(entry->kill_ring, tmp); entry->kill_ring = g_slist_append(entry->kill_ring, tmp); @@ -608,7 +611,7 @@ void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, CUTBUFFER_UPDATE_OP updat static GUI_ENTRY_CUTBUFFER_REC *get_cutbuffer_rec(GUI_ENTRY_REC *entry, CUTBUFFER_UPDATE_OP update_cutbuffer) { - GUI_ENTRY_CUTBUFFER_REC *tmp = NULL; + GUI_ENTRY_CUTBUFFER_REC *tmp; g_return_val_if_fail(entry != NULL, NULL); -- cgit v1.2.3 From 21c07c006066115af4604e26cd89cf60f94a7d53 Mon Sep 17 00:00:00 2001 From: Xavier G Date: Fri, 13 May 2016 02:27:19 +0200 Subject: Leverage string_policy(). --- src/fe-text/gui-entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 63dda34e..beea2273 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -367,7 +367,7 @@ static int scrlen_str(const char *str) g_return_val_if_fail(str != NULL, 0); str = stripped = strip_codes(str); - if (is_utf8() && g_utf8_validate(str, -1, NULL)) { + if (string_policy(str) == TREAT_STRING_AS_UTF8) { while (*str != '\0') { gunichar c; -- cgit v1.2.3 From 72064de9fe064a7536b501fc470edf75fc393314 Mon Sep 17 00:00:00 2001 From: Xavier G Date: Fri, 13 May 2016 04:19:38 +0200 Subject: Simplify scrlen_str() using string_width(). --- src/fe-text/gui-entry.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index beea2273..949a43d3 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -366,22 +366,8 @@ static int scrlen_str(const char *str) char *stripped; g_return_val_if_fail(str != NULL, 0); - str = stripped = strip_codes(str); - if (string_policy(str) == TREAT_STRING_AS_UTF8) { - - while (*str != '\0') { - gunichar c; - - c = g_utf8_get_char(str); - str = g_utf8_next_char(str); - - len += unichar_isprint(c) ? mk_wcwidth(c) : 1; - } - - } else { - len = strlen(str); - } - + stripped = strip_codes(str); + len = string_width(stripped, -1); g_free(stripped); return len; } -- cgit v1.2.3 From 251d8a686a2717c4b1ab9dfc3599eab75105c076 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 24 Aug 2016 22:29:52 +0200 Subject: Fix an OOB access in the cutbuffer implementation. --- src/fe-text/gui-entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/fe-text/gui-entry.c') diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 82645a8e..f05decd2 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -655,7 +655,7 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ tmp->cutbuffer = g_new(unichar, cutbuffer_new_size+1); memcpy(tmp->cutbuffer, tmpcutbuffer, tmp->cutbuffer_len * sizeof(unichar)); - memcpy(tmp->cutbuffer + tmp->cutbuffer_len * sizeof(unichar), + memcpy(tmp->cutbuffer + tmp->cutbuffer_len, entry->text + entry->pos - size, size * sizeof(unichar)); tmp->cutbuffer_len = cutbuffer_new_size; -- cgit v1.2.3