diff options
author | Vincent Sanders <vince@kyllikki.org> | 2020-07-12 13:47:52 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2020-07-12 13:47:52 +0100 |
commit | 313e5cabba172c79a0a8d2bab0b8a99c204616fc (patch) | |
tree | 201042b08eed3d5f3cebfc09b5c6805e5b447a40 /content/handlers | |
parent | aa0b916492b5be45cb37a579e8bc9ab98e5b68d1 (diff) | |
download | netsurf-313e5cabba172c79a0a8d2bab0b8a99c204616fc.tar.gz netsurf-313e5cabba172c79a0a8d2bab0b8a99c204616fc.tar.bz2 |
ensure the html layout is present for text selection
The text selection operations can be called regardless
of when the html layout box tree is actually
available (e.g. if it is still loading when opened)
This change ensures the layout box tree is available before
attempting to traverse it for a selection operation.
Diffstat (limited to 'content/handlers')
-rw-r--r-- | content/handlers/html/textselection.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/content/handlers/html/textselection.c b/content/handlers/html/textselection.c index 51c6ce1a9..cc08aeff2 100644 --- a/content/handlers/html/textselection.c +++ b/content/handlers/html/textselection.c @@ -444,7 +444,11 @@ selection_copy(struct box *box, */ static unsigned selection_label_subtree(struct box *box, unsigned idx) { - struct box *child = box->children; + struct box *child; + + assert(box != NULL); + + box = box->children; box->byte_offset = idx; @@ -475,6 +479,10 @@ html_textselection_redraw(struct content *c, html_content *html = (html_content *)c; struct rdw_info rdw; + if (html->layout == NULL) { + return NSERROR_INVALID; + } + rdw.inited = false; res = coords_from_range(html->layout, start_idx, end_idx, &rdw, false); @@ -505,6 +513,10 @@ html_textselection_copy(struct content *c, save_text_whitespace before = WHITESPACE_NONE; bool first = true; + if (html->layout == NULL) { + return NSERROR_INVALID; + } + return selection_copy(html->layout, &html->len_ctx, start_idx, @@ -523,6 +535,10 @@ html_textselection_get_end(struct content *c, unsigned *end_idx) html_content *html = (html_content *)c; unsigned root_idx; + if (html->layout == NULL) { + return NSERROR_INVALID; + } + root_idx = 0; *end_idx = selection_label_subtree(html->layout, root_idx); |