1
0
mirror of https://github.com/irssi/irssi.git synced 2024-10-13 05:03:45 -04:00

add new function to set the position in bytes

fixes #752
This commit is contained in:
ailin-nemui 2017-09-13 13:58:00 +02:00
parent 24ad80177b
commit 0468c5d912
3 changed files with 23 additions and 4 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
}
}