Skip to content

Commit fe30b5b

Browse files
committed
fix bindings
1 parent 0c82d8f commit fe30b5b

File tree

3 files changed

+92
-89
lines changed

3 files changed

+92
-89
lines changed

frontends/rioterm/src/bindings/mod.rs

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,7 @@ pub fn default_mouse_bindings() -> Vec<MouseBinding> {
604604
)
605605
}
606606

607-
pub fn default_key_bindings(
608-
unprocessed_config_key_bindings: Vec<ConfigKeyBinding>,
609-
use_navigation_key_bindings: bool,
610-
use_splits: bool,
611-
config_keyboard: ConfigKeyboard,
612-
) -> Vec<KeyBinding> {
607+
pub fn default_key_bindings(config: &rio_backend::config::Config) -> Vec<KeyBinding> {
613608
let mut bindings = bindings!(
614609
KeyBinding;
615610
Key::Named(Copy); Action::Copy;
@@ -724,12 +719,15 @@ pub fn default_key_bindings(
724719
));
725720

726721
bindings.extend(platform_key_bindings(
727-
use_navigation_key_bindings,
728-
use_splits,
729-
config_keyboard,
722+
config.navigation.has_navigation_key_bindings(),
723+
config.navigation.use_split,
724+
config.keyboard,
730725
));
731726

732-
config_key_bindings(unprocessed_config_key_bindings, bindings)
727+
// Add hint bindings
728+
bindings.extend(create_hint_bindings(&config.hints.rules));
729+
730+
config_key_bindings(config.bindings.keys.to_owned(), bindings)
733731
}
734732

735733
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -915,6 +913,87 @@ pub fn config_key_bindings(
915913
bindings
916914
}
917915

916+
/// Create hint bindings from configuration
917+
pub fn create_hint_bindings(
918+
hints_config: &[rio_backend::config::hints::Hint],
919+
) -> Vec<KeyBinding> {
920+
let mut hint_bindings = Vec::new();
921+
922+
for hint_config in hints_config {
923+
if let Some(binding_config) = &hint_config.binding {
924+
// Parse key using the same logic as in convert()
925+
let (key, location) = match binding_config.key.to_lowercase().as_str() {
926+
// Letters
927+
single_char if single_char.len() == 1 => {
928+
(Key::Character(single_char.into()), KeyLocation::Standard)
929+
}
930+
// Named keys
931+
"space" => (Key::Named(Space), KeyLocation::Standard),
932+
"enter" | "return" => (Key::Named(Enter), KeyLocation::Standard),
933+
"escape" | "esc" => (Key::Named(Escape), KeyLocation::Standard),
934+
"tab" => (Key::Named(Tab), KeyLocation::Standard),
935+
"backspace" => (Key::Named(Backspace), KeyLocation::Standard),
936+
"delete" => (Key::Named(Delete), KeyLocation::Standard),
937+
"insert" => (Key::Named(Insert), KeyLocation::Standard),
938+
"home" => (Key::Named(Home), KeyLocation::Standard),
939+
"end" => (Key::Named(End), KeyLocation::Standard),
940+
"pageup" => (Key::Named(PageUp), KeyLocation::Standard),
941+
"pagedown" => (Key::Named(PageDown), KeyLocation::Standard),
942+
"up" => (Key::Named(ArrowUp), KeyLocation::Standard),
943+
"down" => (Key::Named(ArrowDown), KeyLocation::Standard),
944+
"left" => (Key::Named(ArrowLeft), KeyLocation::Standard),
945+
"right" => (Key::Named(ArrowRight), KeyLocation::Standard),
946+
// Function keys
947+
"f1" => (Key::Named(F1), KeyLocation::Standard),
948+
"f2" => (Key::Named(F2), KeyLocation::Standard),
949+
"f3" => (Key::Named(F3), KeyLocation::Standard),
950+
"f4" => (Key::Named(F4), KeyLocation::Standard),
951+
"f5" => (Key::Named(F5), KeyLocation::Standard),
952+
"f6" => (Key::Named(F6), KeyLocation::Standard),
953+
"f7" => (Key::Named(F7), KeyLocation::Standard),
954+
"f8" => (Key::Named(F8), KeyLocation::Standard),
955+
"f9" => (Key::Named(F9), KeyLocation::Standard),
956+
"f10" => (Key::Named(F10), KeyLocation::Standard),
957+
"f11" => (Key::Named(F11), KeyLocation::Standard),
958+
"f12" => (Key::Named(F12), KeyLocation::Standard),
959+
_ => {
960+
tracing::warn!(
961+
"Unknown key '{}' in hint binding",
962+
binding_config.key
963+
);
964+
continue;
965+
}
966+
};
967+
968+
// Parse modifiers
969+
let mut mods = ModifiersState::empty();
970+
for mod_str in &binding_config.mods {
971+
match mod_str.to_lowercase().as_str() {
972+
"control" | "ctrl" => mods |= ModifiersState::CONTROL,
973+
"shift" => mods |= ModifiersState::SHIFT,
974+
"alt" | "option" => mods |= ModifiersState::ALT,
975+
"super" | "cmd" | "command" => mods |= ModifiersState::SUPER,
976+
_ => {
977+
tracing::warn!("Unknown modifier '{}' in hint binding", mod_str);
978+
}
979+
}
980+
}
981+
982+
let hint_binding = KeyBinding {
983+
trigger: BindingKey::Keycode { key, location },
984+
mods,
985+
mode: BindingMode::empty(),
986+
notmode: BindingMode::SEARCH | BindingMode::VI,
987+
action: Action::Hint(std::rc::Rc::new(hint_config.clone())),
988+
};
989+
990+
hint_bindings.push(hint_binding);
991+
}
992+
}
993+
994+
hint_bindings
995+
}
996+
918997
// Macos
919998
#[cfg(all(target_os = "macos", not(test)))]
920999
pub fn platform_key_bindings(

frontends/rioterm/src/renderer/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,8 +843,7 @@ impl Renderer {
843843
context.renderable_content.cursor.content_ref;
844844
}
845845

846-
let force_full_damage = has_active_changed
847-
|| self.is_game_mode_enabled;
846+
let force_full_damage = has_active_changed || self.is_game_mode_enabled;
848847

849848
// Check if we need to render
850849
if !context.renderable_content.pending_update.is_dirty() && !force_full_damage

frontends/rioterm/src/screen/mod.rs

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,7 @@ impl Screen<'_> {
181181

182182
let renderer = Renderer::new(config, font_library);
183183

184-
let bindings = crate::bindings::default_key_bindings(
185-
config.bindings.keys.to_owned(),
186-
config.navigation.has_navigation_key_bindings(),
187-
config.navigation.use_split,
188-
config.keyboard,
189-
);
184+
let bindings = crate::bindings::default_key_bindings(config);
190185

191186
let is_native = config.navigation.is_native();
192187

@@ -259,76 +254,6 @@ impl Screen<'_> {
259254
}
260255
sugarloaf.render();
261256

262-
// Create hint bindings from config
263-
let mut hint_bindings = Vec::new();
264-
for hint_config in &config.hints.rules {
265-
if let Some(binding_config) = &hint_config.binding {
266-
// Parse key using the same logic as in bindings/mod.rs
267-
let (key, location) = match binding_config.key.to_lowercase().as_str() {
268-
"o" => (
269-
rio_window::keyboard::Key::Character("o".into()),
270-
rio_window::keyboard::KeyLocation::Standard,
271-
),
272-
"space" => (
273-
rio_window::keyboard::Key::Named(
274-
rio_window::keyboard::NamedKey::Space,
275-
),
276-
rio_window::keyboard::KeyLocation::Standard,
277-
),
278-
"enter" | "return" => (
279-
rio_window::keyboard::Key::Named(
280-
rio_window::keyboard::NamedKey::Enter,
281-
),
282-
rio_window::keyboard::KeyLocation::Standard,
283-
),
284-
"escape" | "esc" => (
285-
rio_window::keyboard::Key::Named(
286-
rio_window::keyboard::NamedKey::Escape,
287-
),
288-
rio_window::keyboard::KeyLocation::Standard,
289-
),
290-
// Add more keys as needed
291-
single_char if single_char.len() == 1 => (
292-
rio_window::keyboard::Key::Character(single_char.into()),
293-
rio_window::keyboard::KeyLocation::Standard,
294-
),
295-
_ => continue, // Skip unknown keys
296-
};
297-
298-
// Parse modifiers
299-
let mut mods = rio_window::keyboard::ModifiersState::empty();
300-
for mod_str in &binding_config.mods {
301-
match mod_str.as_str() {
302-
"Control" => {
303-
mods |= rio_window::keyboard::ModifiersState::CONTROL
304-
}
305-
"Shift" => mods |= rio_window::keyboard::ModifiersState::SHIFT,
306-
"Alt" => mods |= rio_window::keyboard::ModifiersState::ALT,
307-
"Super" | "Cmd" => {
308-
mods |= rio_window::keyboard::ModifiersState::SUPER
309-
}
310-
_ => {}
311-
}
312-
}
313-
314-
let hint_binding = crate::bindings::KeyBinding {
315-
trigger: crate::bindings::BindingKey::Keycode { key, location },
316-
mods,
317-
mode: crate::bindings::BindingMode::empty(),
318-
notmode: crate::bindings::BindingMode::SEARCH
319-
| crate::bindings::BindingMode::VI,
320-
action: crate::bindings::Action::Hint(std::rc::Rc::new(
321-
hint_config.clone(),
322-
)),
323-
};
324-
hint_bindings.push(hint_binding);
325-
}
326-
}
327-
328-
// Add hint bindings to the main bindings
329-
let mut all_bindings = bindings;
330-
all_bindings.extend(hint_bindings);
331-
332257
Ok(Screen {
333258
search_state: SearchState::default(),
334259
hint_state: HintState::new(config.hints.alphabet.clone()),
@@ -345,7 +270,7 @@ impl Screen<'_> {
345270
mouse: Mouse::new(config.scroll.multiplier, config.scroll.divider),
346271
touchpurpose: TouchPurpose::default(),
347272
renderer,
348-
bindings: all_bindings,
273+
bindings,
349274
clipboard,
350275
last_ime_cursor_pos: None,
351276
})

0 commit comments

Comments
 (0)