Skip to content

Commit

Permalink
chore: regenerate template
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-thevenet committed Oct 3, 2024
1 parent e74ea41 commit 249899d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
45 changes: 28 additions & 17 deletions component-generated/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,36 @@ impl App {
let Some(keymap) = self.config.keybindings.get(&self.mode) else {
return Ok(());
};
if self.components.iter().any(|c| c.is_editing()) {
action_tx.send(Action::RawKeyEvent(key))?;
return Ok(());
}
match keymap.get(&vec![key]) {
Some(action) => {
info!("Got action: {action:?}");
action_tx.send(action.clone())?;
if let Some(action) = keymap.get(&vec![key]) {
info!("Got action: {action:?}");
// Look for components in editing mode
// and that should receive a raw key event instead of the action.
for component in &self.components {
// Is it in editing mode and is the action not in the escape list ?
if component.is_editing() && !component.escape_editing_mode().contains(action) {
info!("Action was sent as raw key");
action_tx.send(Action::RawKeyEvent(key))?;
return Ok(());
}
}
// Send the actual action to components
action_tx.send(action.clone())?;
} else {
// If there is a component in editing mode, send the raw key
if self.components.iter().any(|c| c.is_editing()) {
info!("Got raw key: {key:?}");
action_tx.send(Action::RawKeyEvent(key))?;
return Ok(());
}
_ => {
// If the key was not handled as a single key action,
// then consider it for multi-key combinations.
self.last_tick_key_events.push(key);

// Check for multi-key combinations
if let Some(action) = keymap.get(&self.last_tick_key_events) {
info!("Got action: {action:?}");
action_tx.send(action.clone())?;
}
// If the key was not handled as a single key action,
// then consider it for multi-key combinations.
self.last_tick_key_events.push(key);

// Check for multi-key combinations
if let Some(action) = keymap.get(&self.last_tick_key_events) {
info!("Got action: {action:?}");
action_tx.send(action.clone())?;
}
}
Ok(())
Expand Down
7 changes: 7 additions & 0 deletions component-generated/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ pub trait Component {
fn is_editing(&self) -> bool {
false
}
/// Returns zero or more `Action` that should never be sent as `Action::RawKeyEvent` to this component even if `Self::is_editing` returns `true`.
///
/// # Returns
/// * `Vec<Action>` - A list of `Action` that should never be sent as `Action::RawKeyEvent`.
fn escape_editing_mode(&self) -> Vec<Action> {
vec![]
}
/// Handle incoming events and produce actions if necessary.
///
/// # Arguments
Expand Down

0 comments on commit 249899d

Please sign in to comment.