mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:18:13 +00:00
LibWeb: Implement Selection.collapse_to_start
This commit is contained in:
parent
6d46ebfe8a
commit
bb5da1b4e2
2 changed files with 17 additions and 3 deletions
|
@ -199,9 +199,23 @@ WebIDL::ExceptionOr<void> Selection::set_position(JS::GCPtr<DOM::Node> node, uns
|
|||
}
|
||||
|
||||
// https://w3c.github.io/selection-api/#dom-selection-collapsetostart
|
||||
void Selection::collapse_to_start()
|
||||
WebIDL::ExceptionOr<void> Selection::collapse_to_start()
|
||||
{
|
||||
TODO();
|
||||
// 1. The method must throw InvalidStateError exception if the this is empty.
|
||||
if (!m_range) {
|
||||
return WebIDL::InvalidStateError::create(realm(), "Selection.collapse_to_start() on empty range"sv);
|
||||
}
|
||||
|
||||
// 2. Otherwise, it must create a new range
|
||||
auto new_range = DOM::Range::create(*m_document);
|
||||
|
||||
// 3. Set the start both its start and end to the start of this's range
|
||||
TRY(new_range->set_start(*anchor_node(), m_range->start_offset()));
|
||||
TRY(new_range->set_end(*anchor_node(), m_range->start_offset()));
|
||||
|
||||
// 4. Then set this's range to the newly-created range.
|
||||
m_range = new_range;
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://w3c.github.io/selection-api/#dom-selection-collapsetoend
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue