From d65205506033212c0a9439e7b9e4809e3793aa0e Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Wed, 19 Jan 2022 21:10:07 +0100 Subject: [PATCH 1/3] Add empty_kill_clears_cutbuffer option Adapted revert of 13524b1f76bb. --- src/fe-text/gui-entry.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 25965495..406c3fc1 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -20,6 +20,7 @@ #include "module.h" #include +#include #include #include @@ -772,11 +773,13 @@ static GUI_ENTRY_CUTBUFFER_REC *get_cutbuffer_rec(GUI_ENTRY_REC *entry, CUTBUFFE void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_cutbuffer) { + gboolean clear_enabled; size_t i, w = 0; g_return_if_fail(entry != NULL); + clear_enabled = settings_get_bool("empty_kill_clears_cutbuffer"); - if (size == 0 || entry->pos < size) + if (entry->pos < size || (size == 0 && !clear_enabled)) return; if (update_cutbuffer != CUTBUFFER_UPDATE_NOOP) { @@ -818,7 +821,7 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ case CUTBUFFER_UPDATE_REPLACE: /* put erased text to cutbuffer */ - if (tmp->cutbuffer_len < size) { + if (tmp->cutbuffer_len < size || tmp->cutbuffer == NULL) { g_free(tmp->cutbuffer); tmp->cutbuffer = g_new(unichar, size+1); } @@ -834,6 +837,11 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ } } + if (size == 0 && clear_enabled) { + /* we just wanted to clear the cutbuffer */ + return; + } + if (entry->utf8) while (entry->pos > size + w && i_wcwidth(entry->text[entry->pos - size - w]) == 0) w++; @@ -1498,6 +1506,7 @@ void gui_entry_set_text_and_extents(GUI_ENTRY_REC *entry, GSList *list) void gui_entry_init(void) { + settings_add_bool("lookandfeel", "empty_kill_clears_cutbuffer", FALSE); } void gui_entry_deinit(void) From 75e56297fcdbbe9820d3cac5b093045703d9e8e9 Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Sun, 6 Feb 2022 02:25:19 +0100 Subject: [PATCH 2/3] fix intentation --- src/fe-text/gui-entry.c | 66 ++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 406c3fc1..b4013537 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -795,45 +795,45 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ 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, - entry->text + entry->pos - size, size * sizeof(unichar)); + 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, entry->text + entry->pos - size, + size * sizeof(unichar)); - tmp->cutbuffer_len = cutbuffer_new_size; - tmp->cutbuffer[cutbuffer_new_size] = '\0'; - g_free(tmpcutbuffer); - break; + 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)); + 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; + 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 || tmp->cutbuffer == NULL) { - g_free(tmp->cutbuffer); - tmp->cutbuffer = g_new(unichar, size+1); - } + case CUTBUFFER_UPDATE_REPLACE: + /* put erased text to cutbuffer */ + if (tmp->cutbuffer_len < size || tmp->cutbuffer == NULL) { + 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; + 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; + case CUTBUFFER_UPDATE_NOOP: + /* cannot happen, handled in "if" */ + break; } } From e5d02bd57b05bdc05ed4c38adcf7548d7d5048b2 Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Sun, 6 Feb 2022 14:22:56 +0100 Subject: [PATCH 3/3] simplify --- src/fe-text/gui-entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index b4013537..5050c800 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -837,7 +837,7 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_ } } - if (size == 0 && clear_enabled) { + if (size == 0) { /* we just wanted to clear the cutbuffer */ return; }