From fc395d40681bdd76b7262d536668ffc093c5246d Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 22 Oct 2016 23:29:29 +0200 Subject: Fix mouse clicks on full width characters --- src/sdtui.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/sdtui.c b/src/sdtui.c index 0b4bd22..a11646a 100644 --- a/src/sdtui.c +++ b/src/sdtui.c @@ -954,7 +954,7 @@ app_redraw_top (Application *self) guint offset, i; for (offset = i = 0; i < self->input_pos; i++) - // This may be inconsistent with RowBuffer + // FIXME: this may be inconsistent with RowBuffer (locale) offset += unichar_width (g_array_index (self->input, gunichar, i)); move (1, MIN ((gint) (indent + offset), COLS - 1)); @@ -1741,9 +1741,18 @@ app_process_left_mouse_click (Application *self, int line, int column) gint pos = column - label_len; if (pos >= 0) { - self->input_pos = MIN ((guint) pos, self->input->len); - move (1, label_len + self->input_pos); - refresh (); + guint offset, i; + for (offset = i = 0; i < self->input->len; i++) + { + // FIXME: this may be inconsistent with RowBuffer (locale) + size_t width = unichar_width + (g_array_index (self->input, gunichar, i)); + if ((offset += width) > (guint) pos) + break; + } + + self->input_pos = i; + app_redraw_top (self); } } else if (line <= (int) (app_count_view_items (self) - self->top_offset)) -- cgit v1.2.3-70-g09d2