LibWeb: Implement Selection::direction

This commit is contained in:
Gingeh 2024-10-13 14:38:25 +11:00 committed by Andreas Kling
commit a7953f5e09
Notes: github-actions[bot] 2024-10-13 07:48:08 +00:00
3 changed files with 11 additions and 0 deletions

View file

@ -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<JS::GCPtr<DOM::Range>> Selection::get_range_at(unsigned index)
{

View file

@ -33,6 +33,7 @@ public:
bool is_collapsed() const;
unsigned range_count() const;
String type() const;
String direction() const;
WebIDL::ExceptionOr<JS::GCPtr<DOM::Range>> get_range_at(unsigned index);
void add_range(JS::NonnullGCPtr<DOM::Range>);
WebIDL::ExceptionOr<void> remove_range(JS::NonnullGCPtr<DOM::Range>);

View file

@ -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);