Skipping over pseudo contexts has fixed most of the tests.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::renderer::context_element::ContextElement;
|
||||
use crate::renderer::context_element::Walkable;
|
||||
use crate::renderer::WalkError;
|
||||
use std::borrow::Borrow;
|
||||
|
||||
@@ -34,6 +35,17 @@ where
|
||||
WalkResult::FullyWalked(output)
|
||||
}
|
||||
|
||||
pub fn get_first_non_pseudo_element<'a, B>(breadcrumbs: &'a Vec<B>) -> Option<&B>
|
||||
where
|
||||
B: Borrow<dyn ContextElement + 'a>,
|
||||
{
|
||||
breadcrumbs
|
||||
.iter()
|
||||
.rev()
|
||||
.filter(|b| !(*b).borrow().is_pseudo_element())
|
||||
.next()
|
||||
}
|
||||
|
||||
pub fn walk_path<'a, B, P>(
|
||||
breadcrumbs: &'a Vec<B>,
|
||||
path: &Vec<P>,
|
||||
@@ -60,17 +72,22 @@ where
|
||||
.borrow()
|
||||
== "."
|
||||
{
|
||||
return match walk_path_from_single_level(
|
||||
breadcrumbs
|
||||
.last()
|
||||
.expect("Breadcrumbs should never be empty"),
|
||||
&path[1..],
|
||||
) {
|
||||
// If no walking was done at all or we partially walked
|
||||
// then stop trying to find anything because '.' restricts
|
||||
// us to the current scope
|
||||
WalkResult::NoWalk | WalkResult::PartialWalk => Err(WalkError::CantWalk),
|
||||
WalkResult::FullyWalked(new_context) => Ok(new_context),
|
||||
let first_non_pseudo_element = get_first_non_pseudo_element(breadcrumbs);
|
||||
// println!(
|
||||
// "First non-pseudo element: {:?}",
|
||||
// first_non_pseudo_element.map(|b| b.borrow())
|
||||
// );
|
||||
return match first_non_pseudo_element {
|
||||
None => Err(WalkError::CantWalk),
|
||||
Some(current_context) => {
|
||||
match walk_path_from_single_level(current_context, &path[1..]) {
|
||||
// If no walking was done at all or we partially walked
|
||||
// then stop trying to find anything because '.' restricts
|
||||
// us to the current scope
|
||||
WalkResult::NoWalk | WalkResult::PartialWalk => Err(WalkError::CantWalk),
|
||||
WalkResult::FullyWalked(new_context) => Ok(new_context),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
for context in breadcrumbs.iter().rev() {
|
||||
|
||||
Reference in New Issue
Block a user