summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Range.cpp14
-rw-r--r--Userland/Libraries/LibWeb/DOM/Range.h1
-rw-r--r--Userland/Libraries/LibWeb/DOM/Range.idl1
3 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Range.cpp b/Userland/Libraries/LibWeb/DOM/Range.cpp
index e30c2b519e..f910dd338a 100644
--- a/Userland/Libraries/LibWeb/DOM/Range.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Range.cpp
@@ -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));
diff --git a/Userland/Libraries/LibWeb/DOM/Range.h b/Userland/Libraries/LibWeb/DOM/Range.h
index 9b10cf2f4c..d93daf579e 100644
--- a/Userland/Libraries/LibWeb/DOM/Range.h
+++ b/Userland/Libraries/LibWeb/DOM/Range.h
@@ -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 {
diff --git a/Userland/Libraries/LibWeb/DOM/Range.idl b/Userland/Libraries/LibWeb/DOM/Range.idl
index d5fb24f1a7..ef42bbe2c2 100644
--- a/Userland/Libraries/LibWeb/DOM/Range.idl
+++ b/Userland/Libraries/LibWeb/DOM/Range.idl
@@ -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;