diff options
author | Thomas White <taw@bitwiz.org.uk> | 2013-03-20 09:25:59 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2013-03-20 09:25:59 +0100 |
commit | 4fdde18f9a8b266dc37217816b0b9b369f1e7eec (patch) | |
tree | 8e7905a94ff1606a759e721ef2af1d01646286db /src | |
parent | 74d0c61a292161a3d280eafb2d2894460335f4bd (diff) |
More cursor position stuff
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.c | 48 | ||||
-rw-r--r-- | src/wrap.c | 8 |
2 files changed, 54 insertions, 2 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c index 86109cd..4ee16d5 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -947,6 +947,23 @@ static gboolean im_commit_sig(GtkIMContext *im, gchar *str, } +static void move_cursor(struct presentation *p, signed int x, signed int y) +{ + ssize_t pos = p->cursor_pos; + + pos += x; + + if ( pos < 0 ) pos = 0; + + if ( pos > strlen(p->selection[0]->sc) ) { + pos = strlen(p->selection[0]->sc); + } + + p->selection[0]->pos = pos; + p->cursor_pos = pos; +} + + static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, struct presentation *p) { @@ -973,8 +990,37 @@ static gboolean key_press_sig(GtkWidget *da, GdkEventKey *event, redraw_editor(p); break; + case GDK_KEY_Left : + if ( p->n_selection == 1 ) { + move_cursor(p, -1, 0); + redraw_editor(p); + } + break; + + case GDK_KEY_Right : + if ( p->n_selection == 1 ) { + move_cursor(p, +1, 0); + redraw_editor(p); + } + break; + + case GDK_KEY_Up : + if ( p->n_selection == 1 ) { + move_cursor(p, -1, -1); + redraw_editor(p); + } + break; + + case GDK_KEY_Down : + if ( p->n_selection == 1 ) { + move_cursor(p, +1, +1); + redraw_editor(p); + } + break; + + case GDK_KEY_Return : - //im_commit(p->editing_object, "\n"); FIXME! + im_commit_sig(NULL, "\n", p); break; case GDK_KEY_B : @@ -110,16 +110,22 @@ void get_cursor_pos(struct frame *fr, size_t pos, box = i; if ( l->boxes[i+1].sc_offset > pos ) break; *xposd += l->boxes[i].width; - *xposd += l->boxes[i].sp; + if ( i < l->n_boxes-2 ) { + *xposd += l->boxes[i].sp; + printf("%f\n", l->boxes[i].sp); + } } b = &l->boxes[box]; pango_glyph_string_index_to_x(b->glyphs, b->text, strlen(b->text), &b->item->analysis, pos - b->sc_offset, FALSE, &p); + printf("offset %i in '%s' -> %i\n", pos-b->sc_offset, b->text, p); + *xposd += p; *xposd /= PANGO_SCALE; *xposd += fr->lop.pad_l; + printf("%i -> line %i, box %i -> %f, %f\n", pos, line, box, *xposd, *yposd); } |