diff --git a/src/config.rs b/src/config.rs index fc3fd66..ca7332d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -38,7 +38,7 @@ pub struct NodeTypeConfig { impl NodeTypeConfig { pub fn extend(mut self, other: Self) -> Self { - self.style = other.style.extend(self.style); + self.style = self.style.extend(other.style); self.meta.extend(other.meta); self } diff --git a/src/ui.rs b/src/ui.rs index 8ed2334..4e00dc3 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -180,14 +180,6 @@ fn draw_table(f: &mut Frame, rect: Rect, app: &app::App, hb: &Han // TODO : Optimize let is_selected = app.selection().contains(&node); - let ui = if is_focused { - &config.general.focus_ui - } else if is_selected { - &config.general.selection_ui - } else { - &config.general.default_ui - }; - let is_first = index == 0; let is_last = index == dir.total.max(1) - 1; @@ -230,6 +222,25 @@ fn draw_table(f: &mut Frame, rect: Rect, app: &app::App, hb: &Han Ordering::Equal => (0, false, false), }; + let (mut prefix, mut suffix, mut style) = { + let ui = config.general.default_ui.clone(); + (ui.prefix, ui.suffix, ui.style.extend(node_type.style)) + }; + + if is_selected { + let ui = config.general.selection_ui.clone(); + prefix = ui.prefix.or(prefix); + suffix = ui.suffix.or(suffix); + style = style.extend(ui.style); + }; + + if is_focused { + let ui = config.general.focus_ui.clone(); + prefix = ui.prefix.or(prefix); + suffix = ui.suffix.or(suffix); + style = style.extend(ui.style); + }; + let meta = NodeUiMetadata::new( &node, index, @@ -237,8 +248,8 @@ fn draw_table(f: &mut Frame, rect: Rect, app: &app::App, hb: &Han is_before_focus, is_after_focus, tree.unwrap_or_default(), - ui.prefix.to_owned().unwrap_or_default(), - ui.suffix.to_owned().unwrap_or_default(), + prefix.unwrap_or_default(), + suffix.unwrap_or_default(), is_selected, is_focused, dir.total, @@ -253,14 +264,6 @@ fn draw_table(f: &mut Frame, rect: Rect, app: &app::App, hb: &Han .map(|x| Cell::from(x.to_string())) .collect::>(); - let style = if is_focused { - config.general.focus_ui.style.extend(node_type.style) - } else if is_selected { - config.general.selection_ui.style.extend(node_type.style) - } else { - config.general.default_ui.style.extend(node_type.style) - }; - Row::new(cols).style(style.into()) }) .collect::>()