Skip to content

Commit

Permalink
Make command_bar a configurable shortcut
Browse files Browse the repository at this point in the history
This also allows us to use the shortcut widget which
will capture the shortcut and prevent it from showing
up in the text input.
  • Loading branch information
tarkah committed Feb 5, 2024
1 parent d57760a commit 6377c8e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions data/src/config/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct Keys {
pub cycle_previous_buffer: KeyBind,
#[serde(default = "KeyBind::toggle_nick_list")]
pub toggle_nick_list: KeyBind,
#[serde(default = "KeyBind::command_bar")]
pub command_bar: KeyBind,
}

impl Default for Keys {
Expand All @@ -39,6 +41,7 @@ impl Default for Keys {
cycle_next_buffer: KeyBind::cycle_next_buffer(),
cycle_previous_buffer: KeyBind::cycle_previous_buffer(),
toggle_nick_list: KeyBind::toggle_nick_list(),
command_bar: KeyBind::command_bar(),
}
}
}
Expand All @@ -58,6 +61,7 @@ impl Keys {
shortcut(self.cycle_next_buffer.clone(), CycleNextBuffer),
shortcut(self.cycle_previous_buffer.clone(), CyclePreviousBuffer),
shortcut(self.toggle_nick_list.clone(), ToggleNickList),
shortcut(self.command_bar.clone(), CommandBar),
]
}
}
2 changes: 2 additions & 0 deletions data/src/shortcut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub enum Command {
CycleNextBuffer,
CyclePreviousBuffer,
ToggleNickList,
CommandBar,
}

macro_rules! default {
Expand Down Expand Up @@ -108,6 +109,7 @@ impl KeyBind {
default!(cycle_next_buffer, Tab, CTRL);
default!(cycle_previous_buffer, Tab, CTRL | SHIFT);
default!(toggle_nick_list, "m", COMMAND | ALT);
default!(command_bar, "k", COMMAND);

pub fn is_pressed(
&self,
Expand Down
6 changes: 0 additions & 6 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub enum Event {
Escape,
Home,
End,
CommandBar,
}

pub fn events() -> Subscription<Event> {
Expand Down Expand Up @@ -35,11 +34,6 @@ fn filtered_events(event: iced::Event, status: iced::event::Status) -> Option<Ev
key: keyboard::Key::Named(keyboard::key::Named::End),
..
}) if ignored(status) => Some(Event::End),
iced::Event::Keyboard(keyboard::Event::KeyPressed {
key: keyboard::Key::Character(c),
modifiers,
..
}) if c.as_str() == "k" && modifiers.command() => Some(Event::CommandBar),
iced::Event::Window(_, window::Event::CloseRequested) => Some(Event::CloseRequested),
_ => None,
}
Expand Down
8 changes: 7 additions & 1 deletion src/screen/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ impl Dashboard {
});
}
}
CommandBar => {
return self.toggle_command_bar(
&closed_buffers(self, clients),
config,
theme,
);
}
}
}
}
Expand Down Expand Up @@ -618,7 +625,6 @@ impl Dashboard {

Command::perform(task, |_| Message::Close)
}
CommandBar => self.toggle_command_bar(&closed_buffers(self, clients), config, theme),
}
}

Expand Down

0 comments on commit 6377c8e

Please sign in to comment.