diff options
author | Thomas White <taw@bitwiz.me.uk> | 2019-03-10 15:43:42 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.me.uk> | 2019-03-10 15:43:42 +0100 |
commit | 1d0df409c6d00dec67f3ec60674219bce30592a0 (patch) | |
tree | 6b48ba067cc75477b3b3e2e5a5220ca9594bfe2a /libstorycode | |
parent | 0e88cfed0e00a34436c4db3c9b2b8ad422c5a2df (diff) |
Fix some range errors with selection
Diffstat (limited to 'libstorycode')
-rw-r--r-- | libstorycode/gtk/gtknarrativeview.c | 2 | ||||
-rw-r--r-- | libstorycode/narrative.c | 8 | ||||
-rw-r--r-- | libstorycode/narrative_render_cairo.c | 2 |
3 files changed, 9 insertions, 3 deletions
diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c index 211da32..da3d049 100644 --- a/libstorycode/gtk/gtknarrativeview.c +++ b/libstorycode/gtk/gtknarrativeview.c @@ -778,13 +778,13 @@ static void do_backspace(GtkNarrativeView *e, signed int dir) o2 = pos_trail_to_offset(&n->items[p2.para], p2.pos, p2.trail); narrative_delete_block(n, p1.para, o1, p2.para, o2); e->cpos = p1; + unset_selection(e); /* The only paragraphs which still exist and might have been * affected by the deletion are sel_start.para and the one * immediately afterwards. */ rewrap_range(e, p1.para, p1.para+1); update_size(e); - unset_selection(e); emit_change_sig(e); redraw(e); } diff --git a/libstorycode/narrative.c b/libstorycode/narrative.c index f32e8f0..fe1cf0c 100644 --- a/libstorycode/narrative.c +++ b/libstorycode/narrative.c @@ -156,6 +156,7 @@ static void delete_item(Narrative *n, int del) void narrative_delete_block(Narrative *n, int i1, size_t o1, int i2, size_t o2) { int i; + int n_del = 0; int merge = 1; /* Starting item */ @@ -177,9 +178,12 @@ void narrative_delete_block(Narrative *n, int i1, size_t o1, int i2, size_t o2) /* Middle items */ for ( i=i1+1; i<i2; i++ ) { - delete_item(n, i); - i2--; + /* Deleting the item moves all the subsequent items up, so the + * index to be deleted doesn't change. */ + delete_item(n, i1+1); + n_del++; } + i2 -= n_del; /* Last item */ if ( n->items[i2].type == NARRATIVE_ITEM_SLIDE ) { diff --git a/libstorycode/narrative_render_cairo.c b/libstorycode/narrative_render_cairo.c index dc5fb2a..9852db8 100644 --- a/libstorycode/narrative_render_cairo.c +++ b/libstorycode/narrative_render_cairo.c @@ -264,6 +264,8 @@ int narrative_wrap_range(Narrative *n, Stylesheet *stylesheet, PangoLanguage *la w -= n->space_l + n->space_r; sort_positions(&sel_start, &sel_end); + if ( min < 0 ) min = 0; + if ( max >= n->n_items ) max = n->n_items-1; if ( !positions_equal(sel_start, sel_end) ) { struct narrative_item *item; |