1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-08 19:34:14 -04:00

Fix backspace for utf8 wide chars

This commit is contained in:
James Booth 2015-01-17 22:03:22 +00:00
parent ba89297382
commit 89260280d1

View File

@ -588,29 +588,21 @@ _handle_edit(int key_type, const wint_t ch)
static void static void
_handle_backspace(void) _handle_backspace(void)
{ {
int inp_x = getcurx(inp_win); int col = getcurx(inp_win);
int display_size = utf8_display_len(input); int display_size = utf8_display_len(input);
int input_len_utf8 = g_utf8_strlen(input, -1);
roster_reset_search_attempts(); roster_reset_search_attempts();
if (display_size > 0) { if (display_size > 0) {
// if at end, delete last char // if at end, delete last char
if (inp_x >= display_size) { if (col >= display_size) {
gchar *start = g_utf8_substring(input, 0, inp_x-1); gchar *new_input = g_utf8_substring(input, 0, input_len_utf8-1);
for (input_len_bytes = 0; input_len_bytes < strlen(start); input_len_bytes++) { inp_replace_input(new_input);
input[input_len_bytes] = start[input_len_bytes];
}
input[input_len_bytes] = '\0';
g_free(start);
_clear_input();
waddstr(inp_win, input);
wmove(inp_win, 0, inp_x -1);
// if in middle, delete and shift chars left // if in middle, delete and shift chars left
} else if (inp_x > 0 && inp_x < display_size) { } else if (col > 0 && col < display_size) {
gchar *start = g_utf8_substring(input, 0, inp_x - 1); gchar *start = g_utf8_substring(input, 0, col - 1);
gchar *end = g_utf8_substring(input, inp_x, input_len_bytes); gchar *end = g_utf8_substring(input, col, input_len_bytes);
GString *new = g_string_new(start); GString *new = g_string_new(start);
g_string_append(new, end); g_string_append(new, end);
@ -625,11 +617,11 @@ _handle_backspace(void)
_clear_input(); _clear_input();
waddstr(inp_win, input); waddstr(inp_win, input);
wmove(inp_win, 0, inp_x -1); wmove(inp_win, 0, col -1);
} }
// if gone off screen to left, jump left (half a screen worth) // if gone off screen to left, jump left (half a screen worth)
if (inp_x <= pad_start) { if (col <= pad_start) {
pad_start = pad_start - (cols / 2); pad_start = pad_start - (cols / 2);
if (pad_start < 0) { if (pad_start < 0) {
pad_start = 0; pad_start = 0;