Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ impl Application for Centerpiece {
..
}) => self.select_next_entry(),

iced::Event::Keyboard(iced::keyboard::Event::KeyPressed {
key_code: iced::keyboard::KeyCode::N,
modifiers: iced::keyboard::Modifiers::CTRL,
}) => self.select_next_plugin(),

iced::Event::Keyboard(iced::keyboard::Event::KeyPressed {
key_code: iced::keyboard::KeyCode::P,
modifiers: iced::keyboard::Modifiers::CTRL,
}) => self.select_previous_plugin(),

iced::Event::Keyboard(iced::keyboard::Event::KeyPressed {
key_code: iced::keyboard::KeyCode::Enter,
..
Expand Down Expand Up @@ -294,6 +304,45 @@ impl Centerpiece {
)
}

fn select_next_plugin(&mut self) -> iced::Command<Message> {
let accumulated_entries = self
.plugins
.iter()
.map(|plugin| plugin.entries.len())
.scan(0, |acc, len| {
let prev = *acc;
*acc += len;
Some(prev)
})
.find(|&total| total > self.active_entry_index)
.unwrap_or(self.active_entry_index);

self.active_entry_index = accumulated_entries;
self.scroll_to_selected_entry()
}

fn select_previous_plugin(&mut self) -> iced::Command<Message> {
if self.plugins.is_empty() || self.active_entry_index == 0 {
return self.select_first_entry();
}

let accumulated_entries = self
.plugins
.iter()
.map(|plugin| plugin.entries.len())
.scan(0, |acc, len| {
let prev = *acc;
*acc += len;
Some(prev)
})
.take_while(|&total| total < self.active_entry_index)
.last()
.unwrap_or(0);

self.active_entry_index = accumulated_entries;
self.scroll_to_selected_entry()
}

fn register_plugin(&mut self, plugin: crate::model::Plugin) -> iced::Command<Message> {
self.plugins.push(plugin);
self.plugins.sort_by(|a, b| b.priority.cmp(&a.priority));
Expand Down