aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libstorycode/gtk/gtknarrativeview.c2
-rw-r--r--libstorycode/narrative.c8
-rw-r--r--libstorycode/narrative_render_cairo.c2
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;