diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/frame.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/frame.c b/src/frame.c index 4595610..6a5dde3 100644 --- a/src/frame.c +++ b/src/frame.c @@ -930,7 +930,7 @@ static int get_paragraph_offset(Paragraph *para, int nrun) } -static int which_run(Paragraph *para, size_t offs) +static int which_run(Paragraph *para, size_t offs, int inclusive) { int i; size_t t = 0; @@ -938,7 +938,8 @@ static int which_run(Paragraph *para, size_t offs) for ( i=0; i<para->n_runs; i++ ) { struct text_run *run = ¶->runs[i]; t += run_text_len(run); - if ( t >= offs ) return i; + if ( t > offs ) return i; + if ( inclusive && t == offs ) return i; } return para->n_runs; } @@ -954,7 +955,7 @@ size_t pos_trail_to_offset(Paragraph *para, size_t offs, int trail) char *ptr; size_t para_offset_of_run; - nrun = which_run(para, offs); + nrun = which_run(para, offs, 0); if ( nrun == para->n_runs ) { fprintf(stderr, "pos_trail_to_offset: Offset too high\n"); @@ -1018,7 +1019,7 @@ void insert_text_in_paragraph(Paragraph *para, size_t offs, const char *t) size_t run_offs; /* Find which run we are in */ - nrun = which_run(para, offs); + nrun = which_run(para, offs, 1); if ( nrun == para->n_runs ) { fprintf(stderr, "Couldn't find run to insert into.\n"); return; @@ -1066,7 +1067,7 @@ static SCBlock *pos_to_rscblock(struct frame *fr, struct edit_pos p) paraoffs = pos_trail_to_offset(para, p.pos, p.trail); - run = which_run(para, paraoffs); + run = which_run(para, paraoffs, 1); assert(run < para->n_runs); return para->runs[run].rscblock; @@ -1092,7 +1093,7 @@ static SCBlock *pos_to_scblock(struct frame *fr, struct edit_pos p, paraoffs = pos_trail_to_offset(para, p.pos, p.trail); - run = which_run(para, paraoffs); + run = which_run(para, paraoffs, 1); assert(run < para->n_runs); return para->runs[run].scblock; @@ -1113,7 +1114,7 @@ static size_t pos_to_offset(struct frame *fr, struct edit_pos p) /* Offset of this position into the paragraph */ paraoffs = pos_trail_to_offset(para, p.pos, p.trail); - run = which_run(para, paraoffs); + run = which_run(para, paraoffs, 1); assert(run < para->n_runs); /* Offset of this position into the run @@ -1135,7 +1136,7 @@ static int pos_to_run_number(struct frame *fr, struct edit_pos p) paraoffs = pos_trail_to_offset(para, p.pos, p.trail); - run = which_run(para, paraoffs); + run = which_run(para, paraoffs, 1); assert(run < para->n_runs); return run; @@ -1575,7 +1576,7 @@ static SCBlock *split_text_paragraph(struct frame *fr, int pn, size_t pos, } /* Determine which run the cursor is in */ - run = which_run(para, pos); + run = which_run(para, pos, 1); pnew->type = PARA_TYPE_TEXT; pnew->open = para->open; @@ -1705,7 +1706,7 @@ int get_sc_pos(struct frame *fr, int pn, size_t pos, int nrun; struct text_run *run; - nrun = which_run(para, pos); + nrun = which_run(para, pos, 1); if ( nrun == para->n_runs ) { fprintf(stderr, "Couldn't find run to insert into.\n"); return 1; |