Ensure no empty paragraphs before deleting
authorThomas White <taw@physics.org>
Mon, 26 Mar 2018 20:18:53 +0000 (22:18 +0200)
committerThomas White <taw@physics.org>
Mon, 26 Mar 2018 20:20:08 +0000 (22:20 +0200)
src/frame.c
src/sc_editor.c

index c9189d2..5793e97 100644 (file)
@@ -1427,8 +1427,19 @@ void delete_text_from_frame(struct frame *fr, struct edit_pos p1, struct edit_po
 
        sort_positions(&p1, &p2);
 
+       /* To make sure there are no nasty surprises ahead, run through the
+        * paragraphs we're about to touch, and make sure they all have at least
+        * an empty dummy run */
+       for ( i=p1.para; i<=p2.para; i++ ) {
+               struct edit_pos ep;
+               ep.para = i;
+               ep.pos = 0;
+               ep.trail = 0;
+               ensure_run(fr, ep);
+       }
+
        if ( !position_editable(fr, p1) || !position_editable(fr, p2) ) {
-               fprintf(stderr, "Block delete outside editable region\n");
+               fprintf(stderr, "Delete outside editable region\n");
                return;
        }
 
index 897a2a4..a870059 100644 (file)
@@ -748,16 +748,8 @@ static void do_backspace(struct frame *fr, SCEditor *e)
                        show_edit_pos(p1);
                        show_edit_pos(p2);
 
-                       if ( position_editable(e->cursor_frame, p1)
-                         && position_editable(e->cursor_frame, p2) )
-                       {
-
-                               delete_text_from_frame(e->cursor_frame, p1, p2, wrapw);
-                               e->cpos = p2;
-
-                       } else {
-                               fprintf(stderr, "Deleting not editable.\n");
-                       }
+                       delete_text_from_frame(e->cursor_frame, p1, p2, wrapw);
+                       e->cpos = p2;
 
                } else {