diff options
author | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2017-10-05 11:31:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-05 11:31:44 +0200 |
commit | 92dbb1895b84bc9412bea62ce11473daf4dd2618 (patch) | |
tree | 5fc61837ec6ce1777fbc1ff18eb7d4779718385e /src | |
parent | fc8c15fcd75bf271cddf8e1d6c0db77c225dc5e5 (diff) | |
parent | 1f7de4c3bd8cb03af76c14aff71fc535ce9f23de (diff) | |
download | irssi-92dbb1895b84bc9412bea62ce11473daf4dd2618.zip |
Merge pull request #754 from ailin-nemui/fix-752
add new function to set the position in bytes
Diffstat (limited to 'src')
-rw-r--r-- | src/common.h | 2 | ||||
-rw-r--r-- | src/fe-text/gui-entry.c | 20 | ||||
-rw-r--r-- | src/fe-text/gui-entry.h | 1 | ||||
-rw-r--r-- | src/fe-text/gui-readline.c | 6 |
4 files changed, 24 insertions, 5 deletions
diff --git a/src/common.h b/src/common.h index 100d00cb..159f7124 100644 --- a/src/common.h +++ b/src/common.h @@ -6,7 +6,7 @@ #define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */ #define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */ -#define IRSSI_ABI_VERSION 10 +#define IRSSI_ABI_VERSION 11 #define DEFAULT_SERVER_ADD_PORT 6667 #define DEFAULT_SERVER_ADD_TLS_PORT 6697 diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c index f05decd2..e91fcfb3 100644 --- a/src/fe-text/gui-entry.c +++ b/src/fe-text/gui-entry.c @@ -936,6 +936,26 @@ void gui_entry_set_pos(GUI_ENTRY_REC *entry, int pos) gui_entry_draw(entry); } +void gui_entry_set_text_and_pos_bytes(GUI_ENTRY_REC *entry, const char *str, int pos_bytes) +{ + int pos; + const char *ptr; + + g_return_if_fail(entry != NULL); + + gui_entry_set_text(entry, str); + + if (entry->utf8) { + g_utf8_validate(str, pos_bytes, &ptr); + pos = g_utf8_pointer_to_offset(str, ptr); + } else if (term_type == TERM_TYPE_BIG5) + pos = strlen_big5((const unsigned char *)str) - strlen_big5((const unsigned char *)(str + pos_bytes)); + else + pos = pos_bytes; + + gui_entry_set_pos(entry, pos); +} + void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos) { g_return_if_fail(entry != NULL); diff --git a/src/fe-text/gui-entry.h b/src/fe-text/gui-entry.h index 8777f083..000c5f03 100644 --- a/src/fe-text/gui-entry.h +++ b/src/fe-text/gui-entry.h @@ -50,6 +50,7 @@ void gui_entry_set_utf8(GUI_ENTRY_REC *entry, int utf8); void gui_entry_set_text(GUI_ENTRY_REC *entry, const char *str); char *gui_entry_get_text(GUI_ENTRY_REC *entry); char *gui_entry_get_text_and_pos(GUI_ENTRY_REC *entry, int *pos); +void gui_entry_set_text_and_pos_bytes(GUI_ENTRY_REC *entry, const char *str, int pos_bytes); void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str); void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr); diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 2c2eac21..3688f15e 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -878,8 +878,7 @@ static void key_completion(int erase, int backward) g_free(text); if (line != NULL) { - gui_entry_set_text(active_entry, line); - gui_entry_set_pos(active_entry, pos); + gui_entry_set_text_and_pos_bytes(active_entry, line, pos); g_free(line); } } @@ -909,8 +908,7 @@ static void key_check_replaces(void) g_free(text); if (line != NULL) { - gui_entry_set_text(active_entry, line); - gui_entry_set_pos(active_entry, pos); + gui_entry_set_text_and_pos_bytes(active_entry, line, pos); g_free(line); } } |