From bef894ac4fc76a7c163fba44a8127162a6c40d2b Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 25 Aug 2019 22:30:08 +0200 Subject: Fix *bold* etc --- libstorycode/gtk/gtknarrativeview.c | 17 ++++++++++++----- libstorycode/gtk/gtkslideview.c | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'libstorycode/gtk') diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c index 83d6d23..0fe2c59 100644 --- a/libstorycode/gtk/gtknarrativeview.c +++ b/libstorycode/gtk/gtknarrativeview.c @@ -505,10 +505,10 @@ static size_t pos_trail_to_offset(struct narrative_item *item, int offs, int tra return offs; } - char_offs = g_utf8_pointer_to_offset(item->text, item->text+offs); + char_offs = g_utf8_pointer_to_offset(item->layout_text, item->layout_text+offs); char_offs += trail; - ptr = g_utf8_offset_to_pointer(item->text, char_offs); - return ptr - item->text; + ptr = g_utf8_offset_to_pointer(item->layout_text, char_offs); + return ptr - item->layout_text; } @@ -773,6 +773,8 @@ static void do_backspace(GtkNarrativeView *e, signed int dir) { struct edit_pos p1, p2; size_t o1, o2; + struct narrative_item *item1; + struct narrative_item *item2; if ( !positions_equal(e->sel_start, e->sel_end) ) { @@ -789,8 +791,12 @@ static void do_backspace(GtkNarrativeView *e, signed int dir) } sort_positions(&p1, &p2); - o1 = pos_trail_to_offset(&e->n->items[p1.para], p1.pos, p1.trail); - o2 = pos_trail_to_offset(&e->n->items[p2.para], p2.pos, p2.trail); + item1 = &e->n->items[p1.para]; + item2 = &e->n->items[p2.para]; + o1 = pos_trail_to_offset(item1, p1.pos, p1.trail); + o2 = pos_trail_to_offset(item2, p2.pos, p2.trail); + o1 = layout_index_to_text(item1, o1); + o2 = layout_index_to_text(item2, o2); narrative_delete_block(e->n, p1.para, o1, p2.para, o2); e->cpos = p1; unset_selection(e); @@ -833,6 +839,7 @@ static void insert_text(char *t, GtkNarrativeView *e) if ( narrative_item_is_text(e->n, e->cpos.para) ) { size_t off = pos_trail_to_offset(item, e->cpos.pos, e->cpos.trail); + off = layout_index_to_text(item, off); if ( strcmp(t, "\n") == 0 ) { narrative_split_item(e->n, e->cpos.para, off); diff --git a/libstorycode/gtk/gtkslideview.c b/libstorycode/gtk/gtkslideview.c index 9766572..0ec1c5f 100644 --- a/libstorycode/gtk/gtkslideview.c +++ b/libstorycode/gtk/gtkslideview.c @@ -570,8 +570,8 @@ static int find_cursor(SlideItem *item, Stylesheet *stylesheet, pos->para = i-1; pango_layout_xy_to_index(item->paras[i-1].layout, - pango_units_from_double(x), - pango_units_from_double(y - top), + pango_units_from_double(x - padl), + pango_units_from_double(y - top - padt), &pos->pos, &pos->trail); return 0; } -- cgit v1.2.3