Rearrange editability checks when inserting text
authorThomas White <taw@bitwiz.me.uk>
Wed, 28 Mar 2018 12:51:54 +0000 (14:51 +0200)
committerThomas White <taw@bitwiz.me.uk>
Wed, 28 Mar 2018 12:51:54 +0000 (14:51 +0200)
Makes "insert into non-text paragraph" work again

src/frame.c
src/sc_editor.c

index b87a7c3..ab9e0af 100644 (file)
@@ -1024,6 +1024,11 @@ int position_editable(struct frame *fr, struct edit_pos cp)
                return 0;
        }
 
+       if ( para->type != PARA_TYPE_TEXT ) {
+               fprintf(stderr, "Paragraph is not text.\n");
+               return 0;
+       }
+
        paraoffs = pos_trail_to_offset(para, cp.pos, cp.trail);
        run = which_run(para, paraoffs);
        if ( run == para->n_runs ) {
index 7b58c8f..06e7688 100644 (file)
@@ -769,11 +769,6 @@ static void insert_text(char *t, SCEditor *e)
 {
        Paragraph *para;
 
-       if ( !position_editable(e->cursor_frame, e->cpos) ) {
-               fprintf(stderr, "Position not editable\n");
-               return;
-       }
-
        if ( e->sel_active ) {
                do_backspace(e->cursor_frame, e);
        }
@@ -796,6 +791,12 @@ static void insert_text(char *t, SCEditor *e)
                size_t off;
 
                /* Yes. The "easy" case */
+
+               if ( !position_editable(e->cursor_frame, e->cpos) ) {
+                       fprintf(stderr, "Position not editable\n");
+                       return;
+               }
+
                off = pos_trail_to_offset(para, e->cpos.pos, e->cpos.trail);
                insert_text_in_paragraph(para, off, t);
                wrap_paragraph(para, NULL,