From b8cbdb9760f129b23cbcd31894fa7731528fd46d Mon Sep 17 00:00:00 2001 From: Mattias Eriksson Date: Wed, 14 Feb 2024 08:42:54 +0100 Subject: [PATCH] Prevent bound keys from reaching the terminal --- src/main.rs | 5 +---- src/terminal_box.rs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index c41b8b3..4010328 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1099,10 +1099,7 @@ impl Application for App { }; app.set_curr_font_weights_and_stretches(); - let command = Command::batch([ - app.update_config(), - app.update_title(None) - ]); + let command = Command::batch([app.update_config(), app.update_title(None)]); (app, command) } diff --git a/src/terminal_box.rs b/src/terminal_box.rs index 0d6d7b8..e384649 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -35,11 +35,16 @@ use indexmap::IndexSet; use std::{ cell::Cell, cmp, + collections::HashMap, sync::Mutex, 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> { terminal: &'a Mutex, @@ -52,6 +57,7 @@ pub struct TerminalBox<'a, Message> { on_mouse_enter: Option Message + 'a>>, opacity: Option, mouse_inside_boundary: Option, + key_binds: HashMap, } impl<'a, Message> TerminalBox<'a, Message> @@ -70,6 +76,7 @@ where on_mouse_enter: None, opacity: None, mouse_inside_boundary: None, + key_binds: key_binds(), } } @@ -595,6 +602,11 @@ where modifiers, .. }) 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 escape_code = match named { Named::Insert => csi("2", "~", mod_no), @@ -716,6 +728,11 @@ where key, .. }) 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 let character = text.and_then(|c| c.chars().next()).unwrap_or_default(); if character as u32 == 9 || character as u32 == 127 {