Prevent bound keys from reaching the terminal

This commit is contained in:
Mattias Eriksson 2024-02-14 08:42:54 +01:00 committed by Jeremy Soller
parent bb33a616dd
commit b8cbdb9760
2 changed files with 19 additions and 5 deletions

View file

@ -1099,10 +1099,7 @@ impl Application for App {
}; };
app.set_curr_font_weights_and_stretches(); app.set_curr_font_weights_and_stretches();
let command = Command::batch([ let command = Command::batch([app.update_config(), app.update_title(None)]);
app.update_config(),
app.update_title(None)
]);
(app, command) (app, command)
} }

View file

@ -35,11 +35,16 @@ use indexmap::IndexSet;
use std::{ use std::{
cell::Cell, cell::Cell,
cmp, cmp,
collections::HashMap,
sync::Mutex, sync::Mutex,
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use crate::{terminal::Metadata, Terminal, TerminalScroll}; use crate::{
key_bind::{key_binds, KeyBind},
terminal::Metadata,
Action, Terminal, TerminalScroll,
};
pub struct TerminalBox<'a, Message> { pub struct TerminalBox<'a, Message> {
terminal: &'a Mutex<Terminal>, terminal: &'a Mutex<Terminal>,
@ -52,6 +57,7 @@ pub struct TerminalBox<'a, Message> {
on_mouse_enter: Option<Box<dyn Fn() -> Message + 'a>>, on_mouse_enter: Option<Box<dyn Fn() -> Message + 'a>>,
opacity: Option<f32>, opacity: Option<f32>,
mouse_inside_boundary: Option<bool>, mouse_inside_boundary: Option<bool>,
key_binds: HashMap<KeyBind, Action>,
} }
impl<'a, Message> TerminalBox<'a, Message> impl<'a, Message> TerminalBox<'a, Message>
@ -70,6 +76,7 @@ where
on_mouse_enter: None, on_mouse_enter: None,
opacity: None, opacity: None,
mouse_inside_boundary: None, mouse_inside_boundary: None,
key_binds: key_binds(),
} }
} }
@ -595,6 +602,11 @@ where
modifiers, modifiers,
.. ..
}) if state.is_focused => { }) if state.is_focused => {
for (key_bind, _) in self.key_binds.iter() {
if key_bind.matches(modifiers, &Key::Named(named)) {
return Status::Captured;
}
}
let mod_no = calculate_modifier_number(state); let mod_no = calculate_modifier_number(state);
let escape_code = match named { let escape_code = match named {
Named::Insert => csi("2", "~", mod_no), Named::Insert => csi("2", "~", mod_no),
@ -716,6 +728,11 @@ where
key, key,
.. ..
}) if state.is_focused => { }) if state.is_focused => {
for (key_bind, _) in self.key_binds.iter() {
if key_bind.matches(modifiers, &key) {
return Status::Captured;
}
}
//Tab and Delete is handled by the KeyPress event //Tab and Delete is handled by the KeyPress event
let character = text.and_then(|c| c.chars().next()).unwrap_or_default(); let character = text.and_then(|c| c.chars().next()).unwrap_or_default();
if character as u32 == 9 || character as u32 == 127 { if character as u32 == 9 || character as u32 == 127 {