Skip to content

Commit

Permalink
nav
Browse files Browse the repository at this point in the history
  • Loading branch information
wiiznokes committed Aug 29, 2024
1 parent a029622 commit 216ab5e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
16 changes: 16 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use cosmic::app::{command, Core};

use cosmic::iced::advanced::subscription;
use cosmic::iced::keyboard::key::Named;
use cosmic::iced::wayland::actions::layer_surface::{IcedMargin, SctkLayerSurfaceSettings};
use cosmic::iced::wayland::actions::popup::SctkPopupSettings;
use cosmic::iced::wayland::layer_surface::{
Expand All @@ -23,6 +24,7 @@ use futures::executor::block_on;
use crate::config::{Config, CONFIG_VERSION, PRIVATE_MODE};
use crate::db::{self, Db, Entry};
use crate::message::{AppMsg, ConfigMsg};
use crate::navigation::NavigationMessage;
use crate::utils::command_message;
use crate::{clipboard, config, navigation};

Expand Down Expand Up @@ -303,6 +305,19 @@ impl cosmic::Application for AppState {
self.clipboard_state = ClipboardState::Init;
}
AppMsg::Navigation(message) => match message {
navigation::NavigationMessage::Event(e) => {
let message = match e {
Named::Enter => NavigationMessage::Enter,
Named::Escape => NavigationMessage::Quit,
Named::ArrowDown if !self.config.horizontal => NavigationMessage::Next,
Named::ArrowUp if !self.config.horizontal => NavigationMessage::Previous,
Named::ArrowLeft if self.config.horizontal => NavigationMessage::Previous,
Named::ArrowRight if self.config.horizontal => NavigationMessage::Next,
_ => NavigationMessage::None,
};

return command_message(AppMsg::Navigation(message));
}
navigation::NavigationMessage::Next => {
self.focus_next();
}
Expand All @@ -320,6 +335,7 @@ impl cosmic::Application for AppState {
navigation::NavigationMessage::Quit => {
return self.close_popup();
}
NavigationMessage::None => {}
},
AppMsg::Db(inner) => {
block_on(async {
Expand Down
22 changes: 9 additions & 13 deletions src/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub enum NavigationMessage {
Previous,
Enter,
Quit,
Event(cosmic::iced::keyboard::key::Named),
None,
}

#[allow(clippy::collapsible_match)]
Expand All @@ -19,19 +21,13 @@ pub fn sub() -> Subscription<NavigationMessage> {
cosmic::iced::keyboard::Event::KeyPressed { key, .. } => {
match key {
cosmic::iced::keyboard::Key::Named(named) => match named {
cosmic::iced::keyboard::key::Named::Enter => {
Some(NavigationMessage::Enter)
}

cosmic::iced::keyboard::key::Named::Escape => {
Some(NavigationMessage::Quit)
}

cosmic::iced::keyboard::key::Named::ArrowDown => {
Some(NavigationMessage::Next)
}
cosmic::iced::keyboard::key::Named::ArrowUp => {
Some(NavigationMessage::Previous)
cosmic::iced::keyboard::key::Named::Enter
| cosmic::iced::keyboard::key::Named::Escape
| cosmic::iced::keyboard::key::Named::ArrowDown
| cosmic::iced::keyboard::key::Named::ArrowUp
| cosmic::iced::keyboard::key::Named::ArrowLeft
| cosmic::iced::keyboard::key::Named::ArrowRight => {
Some(NavigationMessage::Event(named))
}

/*
Expand Down

0 comments on commit 216ab5e

Please sign in to comment.