From 4dfa8696bdd75de403cbfa74b230b3db7ebe7698 Mon Sep 17 00:00:00 2001 From: wongjiahau Date: Thu, 16 Feb 2023 09:28:41 +0800 Subject: [PATCH] style(tree): increase indentation --- helix-term/src/ui/explore.rs | 4 +-- helix-term/src/ui/tree.rs | 54 +++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/helix-term/src/ui/explore.rs b/helix-term/src/ui/explore.rs index 39cbc212..af431e23 100644 --- a/helix-term/src/ui/explore.rs +++ b/helix-term/src/ui/explore.rs @@ -506,14 +506,14 @@ impl Explorer { surface.set_stringn( area.x, area.y, - " Explorer: press ? for help", + "Explorer: press ? for help", area.width.into(), cx.editor.theme.get("ui.text"), ); surface.set_stringn( area.x, area.y.saturating_add(1), - format!(" [FILTER]: {}", self.state.filter), + format!("[FILTER]: {}", self.state.filter), area.width.into(), cx.editor.theme.get("ui.text"), ); diff --git a/helix-term/src/ui/tree.rs b/helix-term/src/ui/tree.rs index 18275caf..acae40db 100644 --- a/helix-term/src/ui/tree.rs +++ b/helix-term/src/ui/tree.rs @@ -702,7 +702,6 @@ impl TreeView { let params = RenderElemParams { tree: &self.tree, prefix: &"".to_string(), - is_last: true, level: 0, selected: self.selected, filter, @@ -726,8 +725,7 @@ impl TreeView { struct RenderElemParams<'a, T> { tree: &'a Tree, prefix: &'a String, - is_last: bool, - level: u16, + level: usize, selected: usize, filter: &'a str, } @@ -736,20 +734,25 @@ impl TreeView { RenderElemParams { tree, prefix, - is_last, level, selected, filter, }: RenderElemParams, ) -> Vec<(Indent, Node)> { let indent = if level > 0 { - let bar = if is_last { "└" } else { "├" }; - let branch = if tree.is_opened { "┬" } else { "─" }; - format!("{}{}{}", prefix, bar, branch) + let indicator = if tree.item().is_parent() { + if tree.is_opened { + "" + } else { + "" + } + } else { + " " + }; + format!("{}{}", prefix, indicator) } else { "".to_string() }; - let folded_length = tree.children.len(); let head = ( Indent(indent), Node { @@ -766,25 +769,18 @@ impl TreeView { ), }, ); - let prefix = format!("{}{}", prefix, if is_last { " " } else { "│" }); + let prefix = format!("{}{}", prefix, if level == 0 { "" } else { " " }); vec![head] .into_iter() - .chain( - tree.children - .iter() - .enumerate() - .flat_map(|(local_index, elem)| { - let is_last = local_index == folded_length - 1; - render_tree(RenderElemParams { - tree: elem, - prefix: &prefix, - is_last, - level: level + 1, - selected, - filter, - }) - }), - ) + .chain(tree.children.iter().flat_map(|elem| { + render_tree(RenderElemParams { + tree: elem, + prefix: &prefix, + level: level + 1, + selected, + filter, + }) + })) .collect() } @@ -798,8 +794,14 @@ impl TreeView { } else { style }; + let x = area.x.saturating_add(indent_len); + let x = if indent_len > 0 { + x.saturating_add(1) + } else { + x + }; surface.set_stringn( - area.x.saturating_add(indent_len).saturating_add(1), + x, area.y, node.name.clone(), area.width