From dc6118b49b3f5858732ba5a48751a552eedafa11 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 12 Mar 2014 19:52:18 +0100 Subject: Cursor advance stuff --- src/mainwindow.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/mainwindow.c b/src/mainwindow.c index 7c850cd..482ef1c 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -1601,18 +1601,33 @@ static void move_cursor(struct presentation *p, signed int x, signed int y) { struct wrap_line *line = &p->cursor_frame->lines[p->cursor_line]; struct wrap_box *box = &line->boxes[p->cursor_box]; + signed int cp, cb, cl; /* FIXME: Advance past images etc */ - p->cursor_pos += x; + /* FIXME: use g_utf8_find_next_char() or .._prev_char() */ + cp = p->cursor_pos + x; + cb = p->cursor_box; + cl = p->cursor_line; - if ( p->cursor_pos < 0 ) { - p->cursor_pos = 0; - } + if ( cp < 0 ) cp = 0; + + printf("pos=%i, length=%i\n", cp, g_utf8_strlen(box->text, -1)); - if ( p->cursor_pos > g_utf8_strlen(box->text, -1) ) { - p->cursor_pos = 0; + if ( cp > g_utf8_strlen(box->text, -1) ) { + cp = 0; + cb++; + if ( cb >= line->n_boxes ) { + cl++; + if ( cl >= p->cursor_frame->n_lines ) { + cl = p->cursor_frame->n_lines-1; + } + } } + + p->cursor_pos = cp; + p->cursor_box = cb; + p->cursor_line = cl; } -- cgit v1.2.3