mirror of
https://github.com/irssi/irssi.git
synced 2025-04-26 13:01:11 -05:00
Merge pull request #58 from ailin-nemui/erase-cutbuffer
Add empty_kill_clears_cutbuffer option
This commit is contained in:
commit
27008bf447
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
#include <irssi/src/core/misc.h>
|
#include <irssi/src/core/misc.h>
|
||||||
|
#include <irssi/src/core/settings.h>
|
||||||
#include <irssi/src/core/utf8.h>
|
#include <irssi/src/core/utf8.h>
|
||||||
#include <irssi/src/fe-common/core/formats.h>
|
#include <irssi/src/fe-common/core/formats.h>
|
||||||
|
|
||||||
@ -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)
|
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_cutbuffer)
|
||||||
{
|
{
|
||||||
|
gboolean clear_enabled;
|
||||||
size_t i, w = 0;
|
size_t i, w = 0;
|
||||||
|
|
||||||
g_return_if_fail(entry != NULL);
|
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;
|
return;
|
||||||
|
|
||||||
if (update_cutbuffer != CUTBUFFER_UPDATE_NOOP) {
|
if (update_cutbuffer != CUTBUFFER_UPDATE_NOOP) {
|
||||||
@ -794,10 +797,9 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_
|
|||||||
switch (update_cutbuffer) {
|
switch (update_cutbuffer) {
|
||||||
case CUTBUFFER_UPDATE_APPEND:
|
case CUTBUFFER_UPDATE_APPEND:
|
||||||
tmp->cutbuffer = g_new(unichar, cutbuffer_new_size + 1);
|
tmp->cutbuffer = g_new(unichar, cutbuffer_new_size + 1);
|
||||||
memcpy(tmp->cutbuffer, tmpcutbuffer,
|
memcpy(tmp->cutbuffer, tmpcutbuffer, tmp->cutbuffer_len * sizeof(unichar));
|
||||||
tmp->cutbuffer_len * sizeof(unichar));
|
memcpy(tmp->cutbuffer + tmp->cutbuffer_len, entry->text + entry->pos - size,
|
||||||
memcpy(tmp->cutbuffer + tmp->cutbuffer_len,
|
size * sizeof(unichar));
|
||||||
entry->text + entry->pos - size, size * sizeof(unichar));
|
|
||||||
|
|
||||||
tmp->cutbuffer_len = cutbuffer_new_size;
|
tmp->cutbuffer_len = cutbuffer_new_size;
|
||||||
tmp->cutbuffer[cutbuffer_new_size] = '\0';
|
tmp->cutbuffer[cutbuffer_new_size] = '\0';
|
||||||
@ -818,14 +820,15 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_
|
|||||||
|
|
||||||
case CUTBUFFER_UPDATE_REPLACE:
|
case CUTBUFFER_UPDATE_REPLACE:
|
||||||
/* put erased text to cutbuffer */
|
/* put erased text to cutbuffer */
|
||||||
if (tmp->cutbuffer_len < size) {
|
if (tmp->cutbuffer_len < size || tmp->cutbuffer == NULL) {
|
||||||
g_free(tmp->cutbuffer);
|
g_free(tmp->cutbuffer);
|
||||||
tmp->cutbuffer = g_new(unichar, size + 1);
|
tmp->cutbuffer = g_new(unichar, size + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp->cutbuffer_len = size;
|
tmp->cutbuffer_len = size;
|
||||||
tmp->cutbuffer[size] = '\0';
|
tmp->cutbuffer[size] = '\0';
|
||||||
memcpy(tmp->cutbuffer, entry->text + entry->pos - size, size * sizeof(unichar));
|
memcpy(tmp->cutbuffer, entry->text + entry->pos - size,
|
||||||
|
size * sizeof(unichar));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CUTBUFFER_UPDATE_NOOP:
|
case CUTBUFFER_UPDATE_NOOP:
|
||||||
@ -834,6 +837,11 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (size == 0) {
|
||||||
|
/* we just wanted to clear the cutbuffer */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (entry->utf8)
|
if (entry->utf8)
|
||||||
while (entry->pos > size + w && i_wcwidth(entry->text[entry->pos - size - w]) == 0)
|
while (entry->pos > size + w && i_wcwidth(entry->text[entry->pos - size - w]) == 0)
|
||||||
w++;
|
w++;
|
||||||
@ -1498,6 +1506,7 @@ void gui_entry_set_text_and_extents(GUI_ENTRY_REC *entry, GSList *list)
|
|||||||
|
|
||||||
void gui_entry_init(void)
|
void gui_entry_init(void)
|
||||||
{
|
{
|
||||||
|
settings_add_bool("lookandfeel", "empty_kill_clears_cutbuffer", FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_entry_deinit(void)
|
void gui_entry_deinit(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user