@@ -298,35 +298,38 @@ void ViewportPaintable::recompute_selection_states(DOM::Range& range)
298
298
}
299
299
300
300
// 2. If it's a text node, mark it as StartAndEnd and return.
301
- if (is<DOM::Text>(*start_container)) {
301
+ if (is<DOM::Text>(*start_container) && !range. start (). node -> is_inert () ) {
302
302
if (auto * paintable = start_container->paintable ())
303
303
paintable->set_selection_state (SelectionState::StartAndEnd);
304
304
return ;
305
305
}
306
306
}
307
307
308
308
// 3. Mark the selection start node as Start (if text) or Full (if anything else).
309
- if (auto * paintable = start_container->paintable ()) {
309
+ if (auto * paintable = start_container->paintable (); paintable && !range. start (). node -> is_inert () ) {
310
310
if (is<DOM::Text>(*start_container))
311
311
paintable->set_selection_state (SelectionState::Start);
312
312
else
313
313
paintable->set_selection_state (SelectionState::Full);
314
314
}
315
315
316
316
// 4. Mark the selection end node as End (if text) or Full (if anything else).
317
- if (auto * paintable = end_container->paintable ()) {
317
+ if (auto * paintable = end_container->paintable (); paintable && !range. end (). node -> is_inert () ) {
318
318
if (is<DOM::Text>(*end_container) || end_container->is_ancestor_of (start_container)) {
319
319
paintable->set_selection_state (SelectionState::End);
320
320
} else {
321
321
paintable->for_each_in_inclusive_subtree ([&](auto & layout_node) {
322
- layout_node.set_selection_state (SelectionState::Full);
322
+ if (!layout_node.dom_node () || !layout_node.dom_node ()->is_inert ())
323
+ layout_node.set_selection_state (SelectionState::Full);
323
324
return TraversalDecision::Continue;
324
325
});
325
326
}
326
327
}
327
328
328
329
// 5. Mark the nodes between start node and end node (in tree order) as Full.
329
330
for (auto * node = start_container->next_in_pre_order (); node && (node->is_before (end_container) || node->is_descendant_of (end_container)); node = node->next_in_pre_order ()) {
331
+ if (node->is_inert ())
332
+ continue ;
330
333
if (auto * paintable = node->paintable ())
331
334
paintable->set_selection_state (SelectionState::Full);
332
335
}
0 commit comments