aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2018-03-28 14:51:54 +0200
committerThomas White <taw@bitwiz.me.uk>2018-03-28 14:51:54 +0200
commit6cb58d80203fab0f58e8e0863d6c17f9fbaf6ea3 (patch)
tree885751258cb330b25abca7a8c5a412d7a41c1e45
parent80717944576ff3fec50b037480c9dd8295b1b1b3 (diff)
Rearrange editability checks when inserting text
Makes "insert into non-text paragraph" work again
-rw-r--r--src/frame.c5
-rw-r--r--src/sc_editor.c11
2 files changed, 11 insertions, 5 deletions
diff --git a/src/frame.c b/src/frame.c
index b87a7c3..ab9e0af 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -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 ) {
diff --git a/src/sc_editor.c b/src/sc_editor.c
index 7b58c8f..06e7688 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -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,