diff options
author | Adrian Lees <adrian@aemulor.com> | 2005-04-16 08:22:57 +0000 |
---|---|---|
committer | Adrian Lees <adrian@aemulor.com> | 2005-04-16 08:22:57 +0000 |
commit | 2f3895f0882e696598665cefcc0468de4cec0bff (patch) | |
tree | 457b620f3b45f504a8611c9b40430f393b78e21b /desktop/selection.c | |
parent | f10db1f6f17d6889b1c5043f36b89fe434ed9d0c (diff) | |
download | netsurf-2f3895f0882e696598665cefcc0468de4cec0bff.tar.gz netsurf-2f3895f0882e696598665cefcc0468de4cec0bff.tar.bz2 |
[project @ 2005-04-16 08:22:57 by adrianl]
first cut at selecting inter-block spaces
svn path=/import/netsurf/; revision=1652
Diffstat (limited to 'desktop/selection.c')
-rw-r--r-- | desktop/selection.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/desktop/selection.c b/desktop/selection.c index 291831723..afec4180a 100644 --- a/desktop/selection.c +++ b/desktop/selection.c @@ -656,26 +656,32 @@ void selection_set_end(struct selection *s, struct box *box, int idx) bool selection_highlighted(struct selection *s, struct box *box, unsigned *start_idx, unsigned *end_idx) { - if (selection_defined(s) && box->length > 0 && - box->byte_offset < s->end_idx && - box->byte_offset + box->length > s->start_idx) { - unsigned offset = 0; - unsigned len; + assert(selection_defined(s)); /* caller should have checked for efficiency */ + assert(s && box); - if (box->byte_offset < s->start_idx) - offset = s->start_idx - box->byte_offset; + if (box->length > 0) { + unsigned box_len = box->length + (box->space ? 1 : 0); - len = box->length - offset; - - if (box->byte_offset + box->length > s->end_idx) - len = s->end_idx - (box->byte_offset + offset); - - assert(offset < box->length); - assert(offset + len <= box->length); - - *start_idx = offset; - *end_idx = offset + len; - return true; + if (box->byte_offset < s->end_idx && + box->byte_offset + box_len > s->start_idx) { + unsigned offset = 0; + unsigned len; + + if (box->byte_offset < s->start_idx) + offset = s->start_idx - box->byte_offset; + + len = box_len - offset; + + if (box->byte_offset + box_len > s->end_idx) + len = s->end_idx - (box->byte_offset + offset); + + assert(offset <= box_len); + assert(offset + len <= box->length + 1); + + *start_idx = offset; + *end_idx = offset + len; + return true; + } } return false; } |