Skip to main content

jellyflow_runtime/runtime/keyboard/
types.rs

1use keyboard_types::Code as KeyCode;
2
3use crate::runtime::delete::DeleteSelectionError;
4use crate::runtime::drag::NodeNudgeRequest;
5use crate::runtime::store::{DispatchError, DispatchOutcome};
6
7/// High-level keyboard intent handled by the headless runtime.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum KeyboardIntent {
10    /// Delete the current selection without checking a key binding.
11    DeleteSelection,
12    /// Delete the current selection if the provided key matches the configured binding.
13    DeleteSelectionForKey(KeyCode),
14    /// Nudge the current selected nodes.
15    NudgeSelection(NodeNudgeRequest),
16}
17
18/// Whether a keyboard delete action was explicit or key-bound.
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum KeyboardDeleteAction {
21    ExplicitSelectionDelete,
22    KeyBoundSelectionDelete(KeyCode),
23}
24
25/// Outcome returned by `NodeGraphStore::apply_keyboard_intent`.
26#[derive(Debug, Clone)]
27pub enum KeyboardActionOutcome {
28    DeleteSelection {
29        action: KeyboardDeleteAction,
30        dispatch: DispatchOutcome,
31    },
32    NudgeSelection {
33        request: NodeNudgeRequest,
34        dispatch: DispatchOutcome,
35    },
36}
37
38/// Error returned when a keyboard intent fails while routing to its runtime action.
39#[derive(Debug, thiserror::Error)]
40pub enum KeyboardActionError {
41    #[error("delete selection keyboard action failed: {0}")]
42    DeleteSelection(#[from] DeleteSelectionError),
43    #[error("nudge selection keyboard action failed: {0}")]
44    NudgeSelection(#[from] DispatchError),
45}
46
47impl KeyboardActionOutcome {
48    pub fn dispatch(&self) -> &DispatchOutcome {
49        match self {
50            Self::DeleteSelection { dispatch, .. } | Self::NudgeSelection { dispatch, .. } => {
51                dispatch
52            }
53        }
54    }
55}