Skip to content

Commit

Permalink
Return early when styling before mounting.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigogiraoserrao authored and willmcgugan committed Jan 11, 2024
1 parent fe58531 commit 831f775
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/textual/widgets/_directory_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,31 +295,32 @@ def render_label(
node_label = node._label.copy()
node_label.stylize(style)

# If the tree isn't mounted yet we can't use component classes to stylize
# the label fully, so we return early.
if not self.is_mounted:
return node_label

if node._allow_expand:
prefix = ("📂 " if node.is_expanded else "📁 ", base_style + TOGGLE_STYLE)
if self.is_mounted:
node_label.stylize_before(
self.get_component_rich_style(
"directory-tree--folder", partial=True
)
)
node_label.stylize_before(
self.get_component_rich_style("directory-tree--folder", partial=True)
)
else:
prefix = (
"📄 ",
base_style,
)
if self.is_mounted:
node_label.stylize_before(
self.get_component_rich_style("directory-tree--file", partial=True),
)
node_label.stylize_before(
self.get_component_rich_style("directory-tree--file", partial=True),
)
node_label.highlight_regex(
r"\..+$",
self.get_component_rich_style(
"directory-tree--extension", partial=True
),
)

if node_label.plain.startswith(".") and self.is_mounted:
if node_label.plain.startswith("."):
node_label.stylize_before(
self.get_component_rich_style("directory-tree--hidden")
)
Expand Down

0 comments on commit 831f775

Please sign in to comment.