Skip to content

Commit fd76c46

Browse files
authored
feat(gui): deduplicate scopes in sidebar (#19)
* feat(gui): deduplicate scopes in sidebar * fix lint errors
1 parent 24289a8 commit fd76c46

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

core/gui/src/editor/toolbars.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl HierarchySideBar {
132132
solved_cell: &CompileOutputState,
133133
scopes: &mut Vec<Div>,
134134
scope: ScopeAddress,
135+
count: usize,
135136
depth: usize,
136137
) {
137138
let solved_cell_clone_1 = self.solved_cell.clone();
@@ -152,9 +153,14 @@ impl HierarchySideBar {
152153
.flex_1()
153154
.overflow_hidden()
154155
.child(format!(
155-
"{}{}",
156+
"{}{}{}",
156157
std::iter::repeat_n(" ", depth).collect::<String>(),
157158
&scope_state.name,
159+
if count > 1 {
160+
format!(" ({count})")
161+
} else {
162+
"".to_string()
163+
}
158164
))
159165
.on_click(move |_event, _window, cx| {
160166
solved_cell_clone_1.update(cx, |state, cx| {
@@ -181,20 +187,23 @@ impl HierarchySideBar {
181187
),
182188
);
183189
let scope_info = &solved_cell.output.cells[&scope.cell].scopes[&scope.scope];
190+
let mut cells = IndexMap::new();
184191
for elt in scope_info.elts.clone() {
185192
if let SolvedValue::Instance(inst) = &elt {
186-
let scope = solved_cell.output.cells[&inst.cell].root;
187-
self.render_scopes_helper(
188-
solved_cell,
189-
scopes,
190-
ScopeAddress {
191-
scope,
192-
cell: inst.cell,
193-
},
194-
depth + 1,
195-
);
193+
*cells.entry(inst.cell).or_insert(0) += 1;
196194
}
197195
}
196+
197+
for (cell, count) in cells {
198+
let scope = solved_cell.output.cells[&cell].root;
199+
self.render_scopes_helper(
200+
solved_cell,
201+
scopes,
202+
ScopeAddress { scope, cell },
203+
count,
204+
depth + 1,
205+
);
206+
}
198207
for child_scope in scope_info.children.clone() {
199208
self.render_scopes_helper(
200209
solved_cell,
@@ -203,6 +212,7 @@ impl HierarchySideBar {
203212
scope: child_scope,
204213
cell: scope.cell,
205214
},
215+
1,
206216
depth + 1,
207217
);
208218
}
@@ -219,6 +229,7 @@ impl HierarchySideBar {
219229
scope,
220230
cell: state.output.top,
221231
},
232+
1,
222233
0,
223234
);
224235
}

0 commit comments

Comments
 (0)