App: don't bother copying key into element
When we access an element, we always have its key, either because the slab iterator yielded it along side the element or because we used it to get the element from the slab.
This commit is contained in:
parent
d121385c18
commit
147e275823
4 changed files with 32 additions and 43 deletions
|
|
@ -12,8 +12,7 @@ pub fn Outline() -> View {
|
|||
state.assembly.elements
|
||||
.get_clone()
|
||||
.into_iter()
|
||||
.map(|(_, elt)| elt)
|
||||
.sorted_by_key(|elt| elt.id.clone())
|
||||
.sorted_by_key(|(_, elt)| elt.id.clone())
|
||||
.collect()
|
||||
});
|
||||
|
||||
|
|
@ -26,11 +25,11 @@ pub fn Outline() -> View {
|
|||
) {
|
||||
Keyed(
|
||||
list=elements_sorted,
|
||||
view=|elt| {
|
||||
view=|(key, elt)| {
|
||||
let state = use_context::<AppState>();
|
||||
let class = create_memo({
|
||||
move || {
|
||||
if state.selection.with(|sel| sel.contains(&elt.key)) {
|
||||
if state.selection.with(|sel| sel.contains(&key)) {
|
||||
"selected"
|
||||
} else {
|
||||
""
|
||||
|
|
@ -52,14 +51,14 @@ pub fn Outline() -> View {
|
|||
move |event: MouseEvent| {
|
||||
if event.shift_key() {
|
||||
state.selection.update(|sel| {
|
||||
if !sel.remove(&elt.key) {
|
||||
sel.insert(elt.key);
|
||||
if !sel.remove(&key) {
|
||||
sel.insert(key);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
state.selection.update(|sel| {
|
||||
sel.clear();
|
||||
sel.insert(elt.key);
|
||||
sel.insert(key);
|
||||
});
|
||||
}
|
||||
event.stop_propagation();
|
||||
|
|
@ -70,14 +69,14 @@ pub fn Outline() -> View {
|
|||
if event.key() == "Enter" {
|
||||
if event.shift_key() {
|
||||
state.selection.update(|sel| {
|
||||
if !sel.remove(&elt.key) {
|
||||
sel.insert(elt.key);
|
||||
if !sel.remove(&key) {
|
||||
sel.insert(key);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
state.selection.update(|sel| {
|
||||
sel.clear();
|
||||
sel.insert(elt.key);
|
||||
sel.insert(key);
|
||||
});
|
||||
}
|
||||
event.prevent_default();
|
||||
|
|
@ -90,7 +89,7 @@ pub fn Outline() -> View {
|
|||
}
|
||||
}
|
||||
},
|
||||
key=|elt| elt.key
|
||||
key=|(key, _)| key.clone()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue