Skip to content

Commit

Permalink
fix indent lines when hiding dotfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
18alantom committed Aug 17, 2024
1 parent 058f968 commit 55e64b3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions fs/Manager.zig
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ pub const Iterator = struct {
pub const Entry = struct {
item: *Item,
depth: usize,
index: usize, // child index
first: bool, // is first child
last: bool, // is last child
selected: bool = false,
Expand Down Expand Up @@ -139,7 +138,6 @@ pub const Iterator = struct {
entry.* = .{
.item = first,
.depth = 0,
.index = 0,
.first = true,
.last = true,
.selected = false,
Expand Down Expand Up @@ -195,15 +193,19 @@ pub const Iterator = struct {
}

const children = try entry.item.children();
var skip_count: usize = 0;
for (0..children.items.len) |index| {
// Required because Items are popped off the stack.
const reverse_index = children.items.len - 1 - index;
const item = children.items[reverse_index];

if (skipChild(item, self.dotfiles)) continue;
if (skipChild(item, self.dotfiles)) {
skip_count += 1;
continue;
}

const child_entry = try self.allocator.create(Entry);
child_entry.* = getEntry(reverse_index, entry.depth, children);
child_entry.* = getEntry(reverse_index, entry.depth, children, skip_count);
try self.stack.append(child_entry);
}
}
Expand All @@ -222,13 +224,17 @@ fn skipChild(item: *Item, dotfiles: bool) bool {
return false;
}

fn getEntry(index: usize, parent_depth: usize, children: ItemList) Iterator.Entry {
fn getEntry(
index: usize,
parent_depth: usize,
children: ItemList,
skip_count: usize,
) Iterator.Entry {
return .{
.item = children.items[index],
.index = index,
.depth = parent_depth + 1,
.first = index == 0,
.last = index == children.items.len - 1,
.first = (index -| skip_count) == 0,
.last = index == children.items.len -| (1 + skip_count),
};
}

Expand Down

0 comments on commit 55e64b3

Please sign in to comment.