LibWeb: Implement Range.collapse

This commit is contained in:
Luke Wilde 2022-01-31 18:42:36 +00:00 committed by Andreas Kling
parent dfdc2ddb9e
commit 2b2dbdc74f
Notes: sideshowbarker 2024-07-17 18:14:28 +09:00
3 changed files with 16 additions and 0 deletions

View file

@ -345,6 +345,20 @@ ExceptionOr<void> Range::select_node(Node& node)
return select(node);
}
// https://dom.spec.whatwg.org/#dom-range-collapse
void Range::collapse(bool to_start)
{
// The collapse(toStart) method steps are to, if toStart is true, set end to start; otherwise set start to end.
if (to_start) {
m_end_container = m_start_container;
m_end_offset = m_start_offset;
return;
}
m_start_container = m_end_container;
m_start_offset = m_end_offset;
}
NonnullRefPtr<Range> Range::clone_range() const
{
return adopt_ref(*new Range(const_cast<Node&>(*m_start_container), m_start_offset, const_cast<Node&>(*m_end_container), m_end_offset));

View file

@ -31,6 +31,7 @@ public:
ExceptionOr<void> set_end_before(Node& node);
ExceptionOr<void> set_end_after(Node& node);
ExceptionOr<void> select_node(Node& node);
void collapse(bool to_start);
// https://dom.spec.whatwg.org/#dom-range-start_to_start
enum HowToCompareBoundaryPoints : u16 {

View file

@ -14,6 +14,7 @@ interface Range : AbstractRange {
undefined setStartAfter(Node node);
undefined setEndBefore(Node node);
undefined setEndAfter(Node node);
undefined collapse(optional boolean toStart = false);
undefined selectNode(Node node);
const unsigned short START_TO_START = 0;