From 775df46d6f7b4ef7c685a81c83ca562c455f7653 Mon Sep 17 00:00:00 2001 From: Tristan Hume Date: Fri, 1 Jul 2016 19:19:47 -0400 Subject: [PATCH] Cargo fmt --- src/highlighting/highlighter.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/highlighting/highlighter.rs b/src/highlighting/highlighter.rs index e8795686..8381d4f3 100644 --- a/src/highlighting/highlighter.rs +++ b/src/highlighting/highlighter.rs @@ -24,8 +24,7 @@ pub struct Highlighter<'a> { /// In most themes this is the majority, hence the usefullness single_selectors: Vec<(Scope, StyleModifier)>, multi_selectors: Vec<(ScopeSelector, StyleModifier)>, - // TODO - // single_cache: HashMap>, + // TODO single_cache: HashMap>, } /// Keeps a stack of scopes and styles as state between highlighting different lines. @@ -157,7 +156,8 @@ impl<'a> Highlighter<'a> { } } } - single_selectors.sort_by(|a,b| b.0.len().cmp(&a.0.len())); + // So that deeper matching selectors get checked first + single_selectors.sort_by(|a, b| b.0.len().cmp(&a.0.len())); Highlighter { theme: theme, @@ -207,34 +207,33 @@ impl<'a> Highlighter<'a> { /// if the last element of `path` was just pushed on to the stack. /// Panics if `path` is empty. pub fn get_new_style(&self, path: &[Scope]) -> StyleModifier { - let last_scope = path[path.len()-1]; + let last_scope = path[path.len() - 1]; let single_res = self.single_selectors .iter() .find(|a| a.0.is_prefix_of(last_scope)); let mult_res = self.multi_selectors .iter() - .filter_map(|&(ref sel, ref style)| { - sel.does_match(path).map(|score| (score, style)) - }) + .filter_map(|&(ref sel, ref style)| sel.does_match(path).map(|score| (score, style))) .max_by_key(|&(score, _)| score); if let Some((score, style)) = mult_res { let mut single_score: f64 = -1.0; - if let Some(&(scope,_)) = single_res { - single_score = (scope.len() as f64) * ((ATOM_LEN_BITS * ((path.len()-1) as u16)) as f64).exp2(); + if let Some(&(scope, _)) = single_res { + single_score = (scope.len() as f64) * + ((ATOM_LEN_BITS * ((path.len() - 1) as u16)) as f64).exp2(); } // println!("multi at {:?} score {:?} single score {:?}", path, score, single_score); if MatchPower(single_score) < score { return style.clone(); } } - if let Some(&(_,ref style)) = single_res { + if let Some(&(_, ref style)) = single_res { return style.clone(); } return StyleModifier { foreground: None, background: None, font_style: None, - } + }; } }