jellyflow_runtime/runtime/keyboard/
store.rs1use crate::runtime::drag::NodeNudgeRequest;
2use crate::runtime::store::NodeGraphStore;
3
4use super::types::{
5 KeyboardActionError, KeyboardActionOutcome, KeyboardDeleteAction, KeyboardIntent,
6};
7
8impl NodeGraphStore {
9 pub fn apply_keyboard_intent(
11 &mut self,
12 intent: KeyboardIntent,
13 ) -> Result<Option<KeyboardActionOutcome>, KeyboardActionError> {
14 match intent {
15 KeyboardIntent::DeleteSelection => self
16 .apply_delete_selection()
17 .map(|result| {
18 result.map(|dispatch| KeyboardActionOutcome::DeleteSelection {
19 action: KeyboardDeleteAction::ExplicitSelectionDelete,
20 dispatch,
21 })
22 })
23 .map_err(KeyboardActionError::from),
24 KeyboardIntent::DeleteSelectionForKey(key) => self
25 .apply_delete_selection_for_key(key)
26 .map(|result| {
27 result.map(|dispatch| KeyboardActionOutcome::DeleteSelection {
28 action: KeyboardDeleteAction::KeyBoundSelectionDelete(key),
29 dispatch,
30 })
31 })
32 .map_err(KeyboardActionError::from),
33 KeyboardIntent::NudgeSelection(request) => {
34 apply_keyboard_nudge(self, request).map(KeyboardActionOutcome::from_nudge)
35 }
36 }
37 }
38}
39
40fn apply_keyboard_nudge(
41 store: &mut NodeGraphStore,
42 request: NodeNudgeRequest,
43) -> Result<Option<(NodeNudgeRequest, crate::runtime::store::DispatchOutcome)>, KeyboardActionError>
44{
45 store
46 .apply_node_nudge(request)
47 .map(|result| result.map(|dispatch| (request, dispatch)))
48 .map_err(KeyboardActionError::from)
49}
50
51impl KeyboardActionOutcome {
52 fn from_nudge(
53 value: Option<(NodeNudgeRequest, crate::runtime::store::DispatchOutcome)>,
54 ) -> Option<Self> {
55 value.map(|(request, dispatch)| Self::NudgeSelection { request, dispatch })
56 }
57}