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.
This commit is contained in:
Vincent Sanders 2020-07-12 13:47:52 +01:00
parent aa0b916492
commit 313e5cabba

View File

@ -444,7 +444,11 @@ selection_copy(struct box *box,
*/ */
static unsigned selection_label_subtree(struct box *box, unsigned idx) 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; box->byte_offset = idx;
@ -475,6 +479,10 @@ html_textselection_redraw(struct content *c,
html_content *html = (html_content *)c; html_content *html = (html_content *)c;
struct rdw_info rdw; struct rdw_info rdw;
if (html->layout == NULL) {
return NSERROR_INVALID;
}
rdw.inited = false; rdw.inited = false;
res = coords_from_range(html->layout, start_idx, end_idx, &rdw, 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; save_text_whitespace before = WHITESPACE_NONE;
bool first = true; bool first = true;
if (html->layout == NULL) {
return NSERROR_INVALID;
}
return selection_copy(html->layout, return selection_copy(html->layout,
&html->len_ctx, &html->len_ctx,
start_idx, start_idx,
@ -523,6 +535,10 @@ html_textselection_get_end(struct content *c, unsigned *end_idx)
html_content *html = (html_content *)c; html_content *html = (html_content *)c;
unsigned root_idx; unsigned root_idx;
if (html->layout == NULL) {
return NSERROR_INVALID;
}
root_idx = 0; root_idx = 0;
*end_idx = selection_label_subtree(html->layout, root_idx); *end_idx = selection_label_subtree(html->layout, root_idx);