This commit is contained in:
Todd Pratt 2015-11-02 03:00:17 +00:00
commit 753da5db9d
3 changed files with 42 additions and 23 deletions

View file

@ -35,21 +35,21 @@ static unichar i_toupper(unichar c)
{ {
if (term_type == TERM_TYPE_UTF8) if (term_type == TERM_TYPE_UTF8)
return g_unichar_toupper(c); return g_unichar_toupper(c);
return c <= 255 ? toupper(c) : c; return (c >= 0 && c <= 255) ? toupper(c) : c;
} }
static unichar i_tolower(unichar c) static unichar i_tolower(unichar c)
{ {
if (term_type == TERM_TYPE_UTF8) if (term_type == TERM_TYPE_UTF8)
return g_unichar_tolower(c); return g_unichar_tolower(c);
return c <= 255 ? tolower(c) : c; return (c >= 0 && c <= 255) ? tolower(c) : c;
} }
static int i_isalnum(unichar c) static int i_isalnum(unichar c)
{ {
if (term_type == TERM_TYPE_UTF8) if (term_type == TERM_TYPE_UTF8)
return (g_unichar_isalnum(c) || mk_wcwidth(c) == 0); return (g_unichar_isalnum(c) || mk_wcwidth(c) == 0);
return c <= 255 ? isalnum(c) : 0; return (c >= 0 && c <= 255) ? isalnum(c) : 0;
} }
GUI_ENTRY_REC *active_entry; GUI_ENTRY_REC *active_entry;
@ -555,16 +555,31 @@ void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer)
return; return;
if (update_cutbuffer) { if (update_cutbuffer) {
/* put erased text to cutbuffer */ if (entry->cutbuffer_len && update_cutbuffer == CUTBUFFER_PREPEND) {
if (entry->cutbuffer_len < size) { int cutbuffer_new_size = entry->cutbuffer_len + size;
g_free(entry->cutbuffer); unichar *tmpcutbuffer = entry->cutbuffer;
entry->cutbuffer = g_new(unichar, size+1); entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1);
}
entry->cutbuffer_len = size; memcpy(entry->cutbuffer, entry->text + entry->pos - size,
entry->cutbuffer[size] = '\0'; size * sizeof(unichar));
memcpy(entry->cutbuffer, entry->text + entry->pos - size, memcpy(entry->cutbuffer + size, tmpcutbuffer,
size * sizeof(unichar));
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));
}
} }
if (entry->utf8) if (entry->utf8)
@ -601,7 +616,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, int repeat)
{ {
int to; int to;
@ -624,7 +639,8 @@ 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,
repeat ? CUTBUFFER_PREPEND : TRUE);
} }
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)

View file

@ -1,6 +1,8 @@
#ifndef __GUI_ENTRY_H #ifndef __GUI_ENTRY_H
#define __GUI_ENTRY_H #define __GUI_ENTRY_H
#define CUTBUFFER_PREPEND 42
typedef struct { typedef struct {
int text_len, text_alloc; /* as shorts, not chars */ int text_len, text_alloc; /* as shorts, not chars */
unichar *text; unichar *text;
@ -43,7 +45,7 @@ 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, int 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, int 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, int repeat);
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);

View file

@ -44,7 +44,7 @@ typedef void (*ENTRY_REDIRECT_ENTRY_FUNC) (const char *line, void *data, SERVER_
typedef struct { typedef struct {
SIGNAL_FUNC func; SIGNAL_FUNC func;
int flags; int flags;
void *data; void *data;
} ENTRY_REDIRECT_REC; } ENTRY_REDIRECT_REC;
@ -68,6 +68,8 @@ static int paste_timeout_id;
static void sig_input(void); static void sig_input(void);
static int key_repeated = FALSE;
void input_listen_init(int handle) void input_listen_init(int handle)
{ {
readtag = g_input_add_poll(handle, readtag = g_input_add_poll(handle,
@ -78,7 +80,7 @@ void input_listen_init(int handle)
void input_listen_deinit(void) void input_listen_deinit(void)
{ {
g_source_remove(readtag); g_source_remove(readtag);
readtag = -1; readtag = -1;
} }
static void handle_key_redirect(int key) static void handle_key_redirect(int key)
@ -101,7 +103,7 @@ static void handle_entry_redirect(const char *line)
ENTRY_REDIRECT_ENTRY_FUNC func; ENTRY_REDIRECT_ENTRY_FUNC func;
void *data; void *data;
gui_entry_set_hidden(active_entry, FALSE); gui_entry_set_hidden(active_entry, FALSE);
func = (ENTRY_REDIRECT_ENTRY_FUNC) redir->func; func = (ENTRY_REDIRECT_ENTRY_FUNC) redir->func;
data = redir->data; data = redir->data;
@ -111,7 +113,7 @@ static void handle_entry_redirect(const char *line)
if (func != NULL) { if (func != NULL) {
func(line, data, active_win->active_server, func(line, data, active_win->active_server,
active_win->active); active_win->active);
} }
} }
@ -361,6 +363,7 @@ static void sig_gui_key_pressed(gpointer keyp)
int ret; int ret;
key = GPOINTER_TO_INT(keyp); key = GPOINTER_TO_INT(keyp);
key_repeated = key == prev_key;
if (redir != NULL && redir->flags & ENTRY_REDIRECT_FLAG_HOTKEY) { if (redir != NULL && redir->flags & ENTRY_REDIRECT_FLAG_HOTKEY) {
handle_key_redirect(key); handle_key_redirect(key);
@ -596,7 +599,7 @@ static void key_backspace(void)
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, key_repeated);
} }
static void key_delete_next_word(void) static void key_delete_next_word(void)
@ -606,7 +609,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, key_repeated);
} }
static void key_delete_to_next_space(void) static void key_delete_to_next_space(void)
@ -1020,8 +1023,6 @@ void gui_readline_init(void)
key_bind("key", NULL, "meta2-5F", "cend", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta2-5F", "cend", (SIGNAL_FUNC) key_combo);
key_bind("key", NULL, "meta2-1;5F", "cend", (SIGNAL_FUNC) key_combo); key_bind("key", NULL, "meta2-1;5F", "cend", (SIGNAL_FUNC) key_combo);
key_bind("key", NULL, "meta-O-M", "return", (SIGNAL_FUNC) key_combo);
/* cursor movement */ /* cursor movement */
key_bind("backward_character", "Move the cursor a character backward", "left", NULL, (SIGNAL_FUNC) key_backward_character); key_bind("backward_character", "Move the cursor a character backward", "left", NULL, (SIGNAL_FUNC) key_backward_character);
key_bind("forward_character", "Move the cursor a character forward", "right", NULL, (SIGNAL_FUNC) key_forward_character); key_bind("forward_character", "Move the cursor a character forward", "right", NULL, (SIGNAL_FUNC) key_forward_character);