aboutsummaryrefslogtreecommitdiff
path: root/src/frame.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-03-18 16:15:53 +0100
committerThomas White <taw@physics.org>2018-03-18 21:35:44 +0100
commitffa123e5ba835bb68b063b017df144fb7f5d05ce (patch)
treee7d0ebd7274e52e7b8b671d6f37bec1a8563108b /src/frame.c
parent61394e51a92e28963d82ded391ccf402a0157b5d (diff)
Disallow insertion and deletion unless scblock==rscblock
Diffstat (limited to 'src/frame.c')
-rw-r--r--src/frame.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/frame.c b/src/frame.c
index 27e2210..a125ce6 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -961,6 +961,40 @@ size_t pos_trail_to_offset(Paragraph *para, size_t offs, int trail)
}
+int position_editable(struct frame *fr, struct edit_pos cp)
+{
+ Paragraph *para;
+ int run;
+ size_t paraoffs;
+
+ if ( fr == NULL ) {
+ fprintf(stderr, "Frame is NULL.\n");
+ return 0;
+ }
+
+ if ( cp.para >= fr->n_paras ) {
+ fprintf(stderr, "Paragraph number is too high!\n");
+ return 0;
+ }
+
+ para = fr->paras[cp.para];
+
+ if ( para->scblock != para->rscblock ) {
+ fprintf(stderr, "Paragraph is not editable.\n");
+ return 0;
+ }
+
+ paraoffs = pos_trail_to_offset(para, cp.pos, cp.trail);
+ run = which_run(para, paraoffs);
+ if ( run == para->n_runs ) {
+ fprintf(stderr, "Couldn't find run!\n");
+ return 0;
+ }
+
+ return (para->runs[run].scblock == para->runs[run].rscblock);
+}
+
+
void insert_text_in_paragraph(Paragraph *para, size_t offs, const char *t)
{
int nrun;
@@ -1391,6 +1425,11 @@ void delete_text_from_frame(struct frame *fr, struct edit_pos p1, struct edit_po
sort_positions(&p1, &p2);
+ if ( !position_editable(fr, p1) || !position_editable(fr, p2) ) {
+ fprintf(stderr, "Block delete outside editable region\n");
+ return;
+ }
+
/* Find SC positions for start and end */
p1scblock = pos_to_scblock(fr, p1, &type1);
p2scblock = pos_to_scblock(fr, p2, &type2);