From fe5ea759dcfd99d1554c4787f7af761e1f1d8d6e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 18 May 2015 22:37:23 +0200 Subject: Cursor fixes --- src/wrap.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/wrap.c b/src/wrap.c index 6559dc3..acfb58d 100644 --- a/src/wrap.c +++ b/src/wrap.c @@ -212,7 +212,7 @@ static int find_cursor_box(struct frame *fr, struct wrap_line *l, } *end = 1; - *x_pos = xposd - x; + *x_pos = x; return l->n_boxes-1; } @@ -249,6 +249,10 @@ void find_cursor(struct frame *fr, double xposd, double yposd, } b = &l->boxes[bn]; *box = bn; + if ( end ) { + *pos = b->len_chars; + return; + } if ( !b->editable ) { *pos = 0; @@ -266,14 +270,23 @@ void find_cursor(struct frame *fr, double xposd, double yposd, case WRAP_BOX_PANGO: x_pos_i = pango_units_from_double(x_pos); - block_text = sc_block_contents(b->scblock); - box_text = g_utf8_offset_to_pointer(block_text, b->offs_char); - /* cast because this function is not const-clean */ - pango_glyph_string_x_to_index(b->glyphs, (char *)box_text, - strlen(box_text), - &b->item->analysis, - x_pos_i, &idx, &trail); - offs = idx + trail; + if ( x_pos_i < b->width ) { + block_text = sc_block_contents(b->scblock); + box_text = g_utf8_offset_to_pointer(block_text, + b->offs_char); + printf("box text '%s'\n", box_text); + /* cast because this function is not const-clean */ + pango_glyph_string_x_to_index(b->glyphs, + (char *)box_text, + strlen(box_text), + &b->item->analysis, + x_pos_i, &idx, &trail); + offs = idx + trail; + /* FIXME: Bug in Pango? */ + if ( offs > b->len_chars ) offs = b->len_chars; + } else { + offs = 0; + }; break; default: -- cgit v1.2.3