Skip to content

Commit 8dbd909

Browse files
fix clippy, collapse ifs (#196)
1 parent c705040 commit 8dbd909

File tree

5 files changed

+59
-57
lines changed

5 files changed

+59
-57
lines changed

src/app.rs

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -521,43 +521,45 @@ impl App {
521521
.constraints([Constraint::Length(1), Constraint::Fill(1)])
522522
.split(right_layout[0]);
523523

524-
if let Some(event) = &self.last_frame_mouse_event {
525-
if self.popup.is_none() && event.kind != MouseEventKind::Moved && !matches!(event.kind, MouseEventKind::Down(_)) {
526-
let position = Position::new(event.column, event.row);
527-
let menu_target = root_layout[0];
528-
let tabs_target = tabs_layout[0];
529-
let tab_content_target = tabs_layout[1];
530-
let data_target = right_layout[1];
531-
if menu_target.contains(position) {
532-
self.set_focus(Focus::Menu);
533-
} else if data_target.contains(position) {
534-
self.set_focus(Focus::Data);
535-
} else if tab_content_target.contains(position) {
536-
self.last_focused_tab();
537-
} else if tabs_target.contains(position) {
538-
match self.state.focus {
539-
Focus::Editor => {
540-
if matches!(event.kind, MouseEventKind::Up(_)) {
541-
self.set_focus(Focus::History);
542-
}
543-
},
544-
Focus::History => {
545-
if matches!(event.kind, MouseEventKind::Up(_)) {
546-
self.set_focus(Focus::Favorites);
547-
}
548-
},
549-
Focus::Favorites => {
550-
if matches!(event.kind, MouseEventKind::Up(_)) {
551-
self.set_focus(Focus::Editor);
552-
}
553-
},
554-
Focus::PopUp => {},
555-
_ => {
556-
self.state.focus = self.last_focused_tab;
557-
},
558-
}
559-
self.last_frame_mouse_event = None;
524+
if let Some(event) = &self.last_frame_mouse_event
525+
&& self.popup.is_none()
526+
&& event.kind != MouseEventKind::Moved
527+
&& !matches!(event.kind, MouseEventKind::Down(_))
528+
{
529+
let position = Position::new(event.column, event.row);
530+
let menu_target = root_layout[0];
531+
let tabs_target = tabs_layout[0];
532+
let tab_content_target = tabs_layout[1];
533+
let data_target = right_layout[1];
534+
if menu_target.contains(position) {
535+
self.set_focus(Focus::Menu);
536+
} else if data_target.contains(position) {
537+
self.set_focus(Focus::Data);
538+
} else if tab_content_target.contains(position) {
539+
self.last_focused_tab();
540+
} else if tabs_target.contains(position) {
541+
match self.state.focus {
542+
Focus::Editor => {
543+
if matches!(event.kind, MouseEventKind::Up(_)) {
544+
self.set_focus(Focus::History);
545+
}
546+
},
547+
Focus::History => {
548+
if matches!(event.kind, MouseEventKind::Up(_)) {
549+
self.set_focus(Focus::Favorites);
550+
}
551+
},
552+
Focus::Favorites => {
553+
if matches!(event.kind, MouseEventKind::Up(_)) {
554+
self.set_focus(Focus::Editor);
555+
}
556+
},
557+
Focus::PopUp => {},
558+
_ => {
559+
self.state.focus = self.last_focused_tab;
560+
},
560561
}
562+
self.last_frame_mouse_event = None;
561563
}
562564
}
563565
let tabs = Tabs::new(vec![" 󰤏 query <alt+2>", "  history <alt+4>", "  favorites <alt+5>"])

src/components/editor.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ impl Editor<'_> {
5959
pub fn transition_vim_state(&mut self, input: Input, app_state: &AppState) -> Result<()> {
6060
match input {
6161
Input { key: Key::Enter, alt: true, .. } | Input { key: Key::Enter, ctrl: true, .. } => {
62-
if !app_state.query_task_running {
63-
if let Some(sender) = &self.command_tx {
64-
sender.send(Action::Query(self.textarea.lines().to_vec(), false, false))?;
65-
self.vim_state = Vim::new(Mode::Normal);
66-
self.vim_state.register_action_handler(self.command_tx.clone())?;
67-
self.cursor_style = Mode::Normal.cursor_style();
68-
}
62+
if !app_state.query_task_running
63+
&& let Some(sender) = &self.command_tx
64+
{
65+
sender.send(Action::Query(self.textarea.lines().to_vec(), false, false))?;
66+
self.vim_state = Vim::new(Mode::Normal);
67+
self.vim_state.register_action_handler(self.command_tx.clone())?;
68+
self.cursor_style = Mode::Normal.cursor_style();
6969
}
7070
},
7171
Input { key: Key::Tab, shift: false, .. } if self.vim_state.mode != Mode::Insert => {

src/components/favorites.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ impl Component for Favorites {
204204
match key.code {
205205
KeyCode::Enter if self.search_focused => {
206206
self.search_focused = false;
207-
if let Some(search) = &self.search {
208-
if search.is_empty() {
209-
self.search = None;
210-
}
207+
if let Some(search) = &self.search
208+
&& search.is_empty()
209+
{
210+
self.search = None;
211211
}
212212
self.list_state = ListState::default().with_selected(Some(0));
213213
},

src/tui.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,22 @@ impl Tui {
6969
}
7070

7171
pub fn tick_rate(mut self, tick_rate: Option<f64>) -> Self {
72-
if tick_rate.is_some() {
73-
self.tick_rate = tick_rate.unwrap()
72+
if let Some(tick_rate) = tick_rate {
73+
self.tick_rate = tick_rate;
7474
};
7575
self
7676
}
7777

7878
pub fn frame_rate(mut self, frame_rate: Option<f64>) -> Self {
79-
if frame_rate.is_some() {
80-
self.frame_rate = frame_rate.unwrap();
79+
if let Some(frame_rate) = frame_rate {
80+
self.frame_rate = frame_rate;
8181
}
8282
self
8383
}
8484

8585
pub fn mouse(mut self, mouse: Option<bool>) -> Self {
86-
if mouse.is_some() {
87-
self.mouse = mouse.unwrap();
86+
if let Some(mouse) = mouse {
87+
self.mouse = mouse;
8888
}
8989
self
9090
}

src/utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ pub fn initialize_panic_handler() -> Result<()> {
4141
.into_hooks();
4242
eyre_hook.install()?;
4343
std::panic::set_hook(Box::new(move |panic_info| {
44-
if let Ok(mut t) = crate::tui::Tui::new() {
45-
if let Err(r) = t.exit() {
46-
error!("Unable to exit Terminal: {:?}", r);
47-
}
44+
if let Ok(mut t) = crate::tui::Tui::new()
45+
&& let Err(r) = t.exit()
46+
{
47+
error!("Unable to exit Terminal: {:?}", r);
4848
}
4949

5050
#[cfg(not(debug_assertions))]

0 commit comments

Comments
 (0)