diff --git a/app-proto/src/display.rs b/app-proto/src/display.rs index 494dd3c..c39e575 100644 --- a/app-proto/src/display.rs +++ b/app-proto/src/display.rs @@ -506,20 +506,7 @@ pub fn Display() -> View { // if we clicked something, select it match clicked { - Some((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); - }) - } - }, + Some((key, _)) => state.select(key, event.shift_key()), None => state.selection.update(|sel| sel.clear()) }; } diff --git a/app-proto/src/main.rs b/app-proto/src/main.rs index 897f9d4..8a012d3 100644 --- a/app-proto/src/main.rs +++ b/app-proto/src/main.rs @@ -25,6 +25,24 @@ impl AppState { 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() { diff --git a/app-proto/src/outline.rs b/app-proto/src/outline.rs index e2cf49c..148f870 100644 --- a/app-proto/src/outline.rs +++ b/app-proto/src/outline.rs @@ -83,18 +83,7 @@ fn ElementOutlineItem(key: ElementKey, element: assembly::Element) -> View { move |event: KeyboardEvent| { match event.key().as_str() { "Enter" => { - 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); - }); - } + state.select(key, event.shift_key()); event.prevent_default(); }, "ArrowRight" if constrained.get() => {