App: factor out the selection routine
This commit is contained in:
parent
17d4ed86e4
commit
f4c9d3d7f4
@ -506,20 +506,7 @@ pub fn Display() -> View {
|
|||||||
|
|
||||||
// if we clicked something, select it
|
// if we clicked something, select it
|
||||||
match clicked {
|
match clicked {
|
||||||
Some((key, _)) => {
|
Some((key, _)) => state.select(key, event.shift_key()),
|
||||||
if event.shift_key() {
|
|
||||||
state.selection.update(|sel| {
|
|
||||||
if !sel.remove(&key) {
|
|
||||||
sel.insert(key);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
state.selection.update(|sel| {
|
|
||||||
sel.clear();
|
|
||||||
sel.insert(key);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => state.selection.update(|sel| sel.clear())
|
None => state.selection.update(|sel| sel.clear())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,24 @@ impl AppState {
|
|||||||
selection: create_signal(FxHashSet::default())
|
selection: create_signal(FxHashSet::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// in single-selection mode, select the element with the given key. in
|
||||||
|
// multiple-selection mode, toggle whether the element with the given key
|
||||||
|
// is selected
|
||||||
|
fn select(&self, key: ElementKey, multi: bool) {
|
||||||
|
if multi {
|
||||||
|
self.selection.update(|sel| {
|
||||||
|
if !sel.remove(&key) {
|
||||||
|
sel.insert(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
self.selection.update(|sel| {
|
||||||
|
sel.clear();
|
||||||
|
sel.insert(key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -83,18 +83,7 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View {
|
|||||||
move |event: KeyboardEvent| {
|
move |event: KeyboardEvent| {
|
||||||
match event.key().as_str() {
|
match event.key().as_str() {
|
||||||
"Enter" => {
|
"Enter" => {
|
||||||
if event.shift_key() {
|
state.select(key, event.shift_key());
|
||||||
state.selection.update(|sel| {
|
|
||||||
if !sel.remove(&key) {
|
|
||||||
sel.insert(key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
state.selection.update(|sel| {
|
|
||||||
sel.clear();
|
|
||||||
sel.insert(key);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
event.prevent_default();
|
event.prevent_default();
|
||||||
},
|
},
|
||||||
"ArrowRight" if constrained.get() => {
|
"ArrowRight" if constrained.get() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user