diff --git a/src/renderer/tree_walking.rs b/src/renderer/tree_walking.rs index 98d1793..dc2892b 100644 --- a/src/renderer/tree_walking.rs +++ b/src/renderer/tree_walking.rs @@ -56,21 +56,15 @@ pub fn walk_path<'a, P>( where P: Borrow, { - /* - match (breadcrumbs.is_empty(), path.first()) { - (true, _) => return Err(WalkError::CantWalk), - (false, None) => { - return breadcrumbs - .last() - .map(|bte| bte.borrow()) - .ok_or(WalkError::CantWalk) - } - (false, Some(path_first)) if path_first.borrow() == "." => { + match (breadcrumbs.last(), path.first()) { + (None, _) => return Err(WalkError::CantWalk), + (Some(last_elem), None) => return Ok(last_elem.borrow()), + (Some(_), Some(path_first)) if path_first.borrow() == "." => { let first_non_pseudo_element = get_first_non_pseudo_element(breadcrumbs); return match first_non_pseudo_element { None => Err(WalkError::CantWalk), Some(current_context) => { - match walk_path_from_single_level(current_context.get_ice(), &path[1..]) { + match walk_path_from_single_level(current_context.borrow(), &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 @@ -80,9 +74,9 @@ where } }; } - (false, Some(path_first)) => { - for context in breadcrumbs.ice_iter() { - match walk_path_from_single_level(context, path) { + (Some(_), Some(path_first)) => { + for context in breadcrumbs.iter().rev() { + match walk_path_from_single_level(context.borrow(), path) { // If no walking was done at all, keep looping WalkResult::NoWalk => {} // If we partially walked then stop trying to find @@ -97,6 +91,4 @@ where } Err(WalkError::CantWalk) - */ - todo!() }