mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibWeb: Update Selection::getRangeAt() spec to handle focus and anchor
Co-authored-by: Jim Broadbent <jim.r.broadbent@gmail.com> Co-authored-by: Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
This commit is contained in:
parent
ceefe7d858
commit
ef3a86f010
Notes:
github-actions[bot]
2024-12-27 10:49:28 +00:00
Author: https://github.com/shlyakpavel Commit: https://github.com/LadybirdBrowser/ladybird/commit/ef3a86f0108 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2925 Reviewed-by: https://github.com/gmta
1 changed files with 9 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/SelectionPrototype.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Node.h>
|
||||
#include <LibWeb/DOM/Position.h>
|
||||
#include <LibWeb/DOM/Range.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
|
@ -134,8 +135,14 @@ String Selection::direction() const
|
|||
// https://w3c.github.io/selection-api/#dom-selection-getrangeat
|
||||
WebIDL::ExceptionOr<GC::Ptr<DOM::Range>> Selection::get_range_at(unsigned index)
|
||||
{
|
||||
// The method must throw an IndexSizeError exception if index is not 0, or if this is empty.
|
||||
if (index != 0 || is_empty())
|
||||
GC::Ptr<DOM::Node> focus = focus_node();
|
||||
GC::Ptr<DOM::Node> anchor = anchor_node();
|
||||
|
||||
// The method must throw an IndexSizeError exception if index is not 0, or if this is empty or either focus or anchor is not in the document tree.
|
||||
auto is_focus_in_document_tree = focus && &focus->document() == document();
|
||||
auto is_anchor_in_document_tree = anchor && &anchor->document() == document();
|
||||
|
||||
if (index != 0 || is_empty() || !is_focus_in_document_tree || !is_anchor_in_document_tree)
|
||||
return WebIDL::IndexSizeError::create(realm(), "Selection.getRangeAt() on empty Selection or with invalid argument"_string);
|
||||
|
||||
// Otherwise, it must return a reference to (not a copy of) this's range.
|
||||
|
|
Loading…
Add table
Reference in a new issue