diff options
author | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2016-02-18 00:18:24 +0100 |
---|---|---|
committer | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2016-02-18 00:18:24 +0100 |
commit | 4650665ee482d4d7c3a44948070076d4fa2c745a (patch) | |
tree | aa3ec25aac61265a6fe98d09d39351593926adeb | |
parent | 6d8b92af8a95443bbcdc65072c41ce9c4d1bfecd (diff) | |
parent | 8723c0fb339dcf58c164fbc741122f9c3657ddea (diff) | |
download | irssi-4650665ee482d4d7c3a44948070076d4fa2c745a.zip |
Merge pull request #414 from toddpratt/master
add an append operation to cut buffer handling
-rw-r--r-- | src/fe-text/gui-entry.c | 45 | ||||
-rw-r--r-- | src/fe-text/gui-entry.h | 1 |
2 files changed, 29 insertions, 17 deletions
diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index 6e13ba4e..27778b2b 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -582,25 +582,36 @@ 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); + 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; - memcpy(entry->cutbuffer, entry->text + entry->pos - size, - size * sizeof(unichar)); - memcpy(entry->cutbuffer + size, tmpcutbuffer, - entry->cutbuffer_len * sizeof(unichar)); + 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'; + 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) { @@ -610,9 +621,9 @@ 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: break; } diff --git a/src/fe-text/gui-entry.h b/src/fe-text/gui-entry.h index 498f95b9..d22a7fb8 100644 --- a/src/fe-text/gui-entry.h +++ b/src/fe-text/gui-entry.h @@ -23,6 +23,7 @@ typedef struct { typedef enum { CUTBUFFER_UPDATE_NOOP, CUTBUFFER_UPDATE_REPLACE, + CUTBUFFER_UPDATE_APPEND, CUTBUFFER_UPDATE_PREPEND } CUTBUFFER_UPDATE_OP; |