From a7953f5e092429be3d51e3de2f26f666315ec912 Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Sun, 13 Oct 2024 14:38:25 +1100 Subject: [PATCH] LibWeb: Implement Selection::direction --- Userland/Libraries/LibWeb/Selection/Selection.cpp | 9 +++++++++ Userland/Libraries/LibWeb/Selection/Selection.h | 1 + Userland/Libraries/LibWeb/Selection/Selection.idl | 1 + 3 files changed, 11 insertions(+) diff --git a/Userland/Libraries/LibWeb/Selection/Selection.cpp b/Userland/Libraries/LibWeb/Selection/Selection.cpp index ab7cbf663b8..84179e83029 100644 --- a/Userland/Libraries/LibWeb/Selection/Selection.cpp +++ b/Userland/Libraries/LibWeb/Selection/Selection.cpp @@ -119,6 +119,15 @@ String Selection::type() const return "Range"_string; } +String Selection::direction() const +{ + if (!m_range || m_direction == Direction::Directionless) + return "none"_string; + if (m_direction == Direction::Forwards) + return "forward"_string; + return "backward"_string; +} + // https://w3c.github.io/selection-api/#dom-selection-getrangeat WebIDL::ExceptionOr> Selection::get_range_at(unsigned index) { diff --git a/Userland/Libraries/LibWeb/Selection/Selection.h b/Userland/Libraries/LibWeb/Selection/Selection.h index c7d342e0fa3..bc9207a5eea 100644 --- a/Userland/Libraries/LibWeb/Selection/Selection.h +++ b/Userland/Libraries/LibWeb/Selection/Selection.h @@ -33,6 +33,7 @@ public: bool is_collapsed() const; unsigned range_count() const; String type() const; + String direction() const; WebIDL::ExceptionOr> get_range_at(unsigned index); void add_range(JS::NonnullGCPtr); WebIDL::ExceptionOr remove_range(JS::NonnullGCPtr); diff --git a/Userland/Libraries/LibWeb/Selection/Selection.idl b/Userland/Libraries/LibWeb/Selection/Selection.idl index a4089eae249..4f9c93e74dc 100644 --- a/Userland/Libraries/LibWeb/Selection/Selection.idl +++ b/Userland/Libraries/LibWeb/Selection/Selection.idl @@ -12,6 +12,7 @@ interface Selection { readonly attribute boolean isCollapsed; readonly attribute unsigned long rangeCount; readonly attribute DOMString type; + readonly attribute DOMString direction; Range getRangeAt(unsigned long index); undefined addRange(Range range); undefined removeRange(Range range);