From a0e2ba2b82470b0dacfb406ba87992be12e4c66d Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 30 May 2020 12:24:50 -0400 Subject: [PATCH] Had to update the 1-behind insertion for partial parameters to account for pseudo elements. --- src/renderer/renderer.rs | 15 ++++++++++++++- src/renderer/walking.rs | 4 ---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index 0de9263..88617db 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -17,6 +17,7 @@ use crate::renderer::inline_partial_tree::InlinePartialTreeElement; use crate::renderer::iteration_context::IterationContext; use crate::renderer::parameters_context::ParametersContext; use crate::renderer::walking::walk_path; +use std::borrow::Borrow; use std::collections::HashMap; #[derive(Clone, Debug)] @@ -813,6 +814,15 @@ impl<'a> DustRenderer<'a> { Some(new_stack) } + fn get_index_of_first_non_pseudo_element<'b, B>(breadcrumbs: &'b Vec) -> Option + where + B: Borrow, + { + breadcrumbs + .iter() + .rposition(|b| !(*b).borrow().is_pseudo_element()) + } + fn new_breadcrumbs_partial<'b>( breadcrumbs: &'b Vec<&'b dyn ContextElement>, explicit_context_breadcrumbs: &'b Vec<&'b dyn ContextElement>, @@ -837,7 +847,10 @@ impl<'a> DustRenderer<'a> { // added after the current context but before the explicit // context. match explicit_context { - None => new_stack.insert(std::cmp::max(new_stack.len() - 1, 0), ctx), + None => new_stack.insert( + Self::get_index_of_first_non_pseudo_element(&new_stack).unwrap_or(0), + ctx, + ), _ => new_stack.push(ctx), } }); diff --git a/src/renderer/walking.rs b/src/renderer/walking.rs index 58cd0b4..c0c2365 100644 --- a/src/renderer/walking.rs +++ b/src/renderer/walking.rs @@ -73,10 +73,6 @@ where == "." { 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) => {