Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
trishume committed Jul 1, 2016
1 parent 0bdd0d7 commit 775df46
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/highlighting/highlighter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Scope, StyleModifier, BuildHasherDefault<FnvHasher>>,
// TODO single_cache: HashMap<Scope, StyleModifier, BuildHasherDefault<FnvHasher>>,
}

/// Keeps a stack of scopes and styles as state between highlighting different lines.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
};
}
}

Expand Down

0 comments on commit 775df46

Please sign in to comment.