diff options
author | Thomas White <taw@bitwiz.org.uk> | 2011-10-04 20:36:40 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2011-10-04 20:36:40 +0200 |
commit | 224be95caab86b030a5cf11d585ffabb34d4daf5 (patch) | |
tree | 791bdf387b69a7106abd01d5a0ed1a9d132886eb /src/tool_text.c | |
parent | e5b22fe37ef3a90345eff9b5fe845df2692e4b8f (diff) |
Fix cursor position handling
Diffstat (limited to 'src/tool_text.c')
-rw-r--r-- | src/tool_text.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/tool_text.c b/src/tool_text.c index 9b11485..0e3e43d 100644 --- a/src/tool_text.c +++ b/src/tool_text.c @@ -49,6 +49,7 @@ struct text_object char *text; size_t text_len; int insertion_point; + int insertion_trail; PangoLayout *layout; PangoFontDescription *fontdesc; double offs_x; @@ -245,31 +246,31 @@ void insert_text(struct object *op, char *t) } -void move_cursor_left(struct object *op) +void move_cursor(struct object *op, int dir) { struct text_object *o = (struct text_object *)op; int new_idx, new_trail; pango_layout_move_cursor_visually(o->layout, TRUE, o->insertion_point, - 0, -1, &new_idx, &new_trail); + o->insertion_trail, + dir, &new_idx, &new_trail); if ( (new_idx >= 0) && (new_idx < G_MAXINT) ) { o->insertion_point = new_idx; + o->insertion_trail = new_trail; } } -void move_cursor_right(struct object *op) +void move_cursor_left(struct object *op) { - struct text_object *o = (struct text_object *)op; - int new_idx, new_trail; + move_cursor(op, -1); +} - pango_layout_move_cursor_visually(o->layout, TRUE, o->insertion_point, - 0, +1, &new_idx, &new_trail); - if ( (new_idx >= 0) && (new_idx < G_MAXINT) ) { - o->insertion_point = new_idx; - } +void move_cursor_right(struct object *op) +{ + move_cursor(op, +1); } @@ -319,7 +320,9 @@ static void draw_caret(cairo_t *cr, struct object *op) assert(o->base.type == TEXT); - pango_layout_get_cursor_pos(o->layout, o->insertion_point, &pos, NULL); + pango_layout_get_cursor_pos(o->layout, + o->insertion_point+o->insertion_trail, + &pos, NULL); xposd = pos.x/PANGO_SCALE; cx = o->base.x - o->offs_x + xposd; @@ -378,6 +381,7 @@ static struct object *add_text_object(struct slide *s, double x, double y, new->text[0] = '\0'; new->text_len = 1; new->insertion_point = 0; + new->insertion_trail = 0; new->layout = pango_layout_new(ti->pc); new->fontdesc = NULL; |