Adjusts code style

Signed-off-by: lfpraca <luisfelippe@protonmail.com>
This commit is contained in:
lfpraca 2025-06-01 14:41:57 -03:00
parent 415f75d5fc
commit 1ae42386f3

View file

@ -42,15 +42,15 @@ pub(crate) struct Selection {
} }
// this should be changed once content-visibility gets implemented to check for content-visibility == visible too // this should be changed once content-visibility gets implemented to check for content-visibility == visible too
fn text_node_is_selectable(text_node: &Text) -> bool { fn text_node_should_be_stringified(text_node: &Text, can_gc: CanGc) -> bool {
text_node text_node
.upcast::<Node>() .upcast::<Node>()
.GetParentElement() .GetParentElement()
.and_then(|p| p.style(CanGc::note())) .and_then(|parent| parent.style(can_gc))
.is_some_and(|s| { .is_some_and(|style| {
!s.get_box().display.is_none() !style.get_box().display.is_none() &&
&& s.get_inherited_box().visibility style.get_inherited_box().visibility ==
== longhands::visibility::computed_value::T::Visible longhands::visibility::computed_value::T::Visible
}) })
} }
@ -532,31 +532,29 @@ impl SelectionMethods<crate::DomTypeHolder> for Selection {
// https://w3c.github.io/selection-api/#dom-selection-stringifier // https://w3c.github.io/selection-api/#dom-selection-stringifier
fn Stringifier(&self) -> DOMString { fn Stringifier(&self) -> DOMString {
if let Some(range) = self.range.get() { let Some(range) = self.range.get() else {
return DOMString::from("");
};
let start_node = range.start_container(); let start_node = range.start_container();
let end_node = range.end_container(); let end_node = range.end_container();
// Step 1. let mut selection_text = DOMString::new();
let mut s = DOMString::new();
if let Some(text_node) = start_node.downcast::<Text>() { if let Some(text_node) = start_node.downcast::<Text>() {
if text_node_is_selectable(text_node) { if text_node_should_be_stringified(text_node, CanGc::note()) {
let char_data = text_node.upcast::<CharacterData>(); let char_data = text_node.upcast::<CharacterData>();
// Step 2.
if start_node == end_node { if start_node == end_node {
let r = char_data return char_data
.SubstringData( .SubstringData(
range.start_offset(), range.start_offset(),
range.end_offset() - range.start_offset(), range.end_offset() - range.start_offset(),
) )
.unwrap(); .unwrap();
return r;
} }
// Step 3. selection_text.push_str(
s.push_str(
&char_data &char_data
.SubstringData( .SubstringData(
range.start_offset(), range.start_offset(),
@ -565,32 +563,29 @@ impl SelectionMethods<crate::DomTypeHolder> for Selection {
.unwrap(), .unwrap(),
); );
} else if start_node == end_node { } else if start_node == end_node {
return s; return selection_text;
} }
} }
// Step 4.
let ancestor = range.CommonAncestorContainer(); let ancestor = range.CommonAncestorContainer();
for child in start_node for child in start_node
.following_nodes(&ancestor) .following_nodes(&ancestor)
.filter_map(DomRoot::downcast::<Text>) .filter_map(DomRoot::downcast::<Text>)
.filter(|t| text_node_is_selectable(t) && range.contains(t.upcast())) .filter(|text_node| {
text_node_should_be_stringified(text_node, CanGc::note()) &&
range.contains(text_node.upcast())
})
{ {
s.push_str(&child.upcast::<CharacterData>().Data()); selection_text.push_str(&child.upcast::<CharacterData>().Data());
} }
// Step 5.
if let Some(text_node) = end_node.downcast::<Text>() { if let Some(text_node) = end_node.downcast::<Text>() {
if text_node_is_selectable(text_node) { if text_node_should_be_stringified(text_node, CanGc::note()) {
let char_data = text_node.upcast::<CharacterData>(); let char_data = text_node.upcast::<CharacterData>();
s.push_str(&char_data.SubstringData(0, range.end_offset()).unwrap()); selection_text.push_str(&char_data.SubstringData(0, range.end_offset()).unwrap());
} }
} }
// Step 6. selection_text
s
} else {
DOMString::from("")
}
} }
} }