From 6c990b5bda4e5ec00c38661094c53fab2635adf6 Mon Sep 17 00:00:00 2001 From: Thomas Frans Date: Sun, 4 Jun 2023 20:07:46 +0200 Subject: [PATCH] fix: config option `command_key` not working --- src/config.rs | 1 + src/ui/layout.rs | 53 +++++++++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/config.rs b/src/config.rs index 1dfedfe..2a57fb5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,6 +14,7 @@ use crate::serialization::{Serializer, CBOR, TOML}; pub const CLIENT_ID: &str = "d420a117a32841c2b3474932e49fb54b"; pub const CACHE_VERSION: u16 = 1; +pub const DEFAULT_COMMAND_KEY: char = ':'; /// The playback state when ncspot is started. #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] diff --git a/src/ui/layout.rs b/src/ui/layout.rs index 8224c6f..ebae03d 100644 --- a/src/ui/layout.rs +++ b/src/ui/layout.rs @@ -17,7 +17,7 @@ use unicode_width::UnicodeWidthStr; use crate::application::UserData; use crate::command::{self, Command, JumpMode}; use crate::commands::CommandResult; -use crate::config::Config; +use crate::config::{self, Config}; use crate::events; use crate::ext_traits::CursiveExt; use crate::traits::{IntoBoxedViewExt, ViewExt}; @@ -358,28 +358,43 @@ impl View for Layout { fn on_event(&mut self, event: Event) -> EventResult { match event { - Event::Char(':') | Event::Char('/') => { - let result = if let Some(view) = self.get_current_view_mut() { - view.on_event(event.relativized((0, 1))) - } else { - EventResult::Ignored - }; - - if let EventResult::Ignored = result { - if let Event::Char(':') = event { - let command_key = self.configuration.values().command_key.unwrap_or(':'); - self.enable_cmdline(command_key); - } else { - self.enable_jump(); - } - } else { - return EventResult::Ignored; - } - } Event::Key(Key::Esc) if self.cmdline_focus => self.clear_cmdline(), _ if self.cmdline_focus => { return self.command_line_handle_event(event); } + Event::Char(character) + if !self.cmdline_focus + && (character + == self + .configuration + .values() + .command_key + .unwrap_or(config::DEFAULT_COMMAND_KEY) + || character == '/') => + { + let result = self + .get_current_view_mut() + .map(|view| view.on_event(event)) + .unwrap_or(EventResult::Ignored); + + if let EventResult::Ignored = result { + let command_key = self + .configuration + .values() + .command_key + .unwrap_or(config::DEFAULT_COMMAND_KEY); + + if character == command_key { + self.enable_cmdline(command_key); + } else if character == '/' { + self.enable_jump(); + } else { + return EventResult::Ignored; + } + } else { + return result; + } + } Event::Mouse { position, event: mouse_event,