From e6f0d5ce01a296715d0d52755a71068a88a8bf1f Mon Sep 17 00:00:00 2001 From: Jeff Zhao Date: Sat, 12 Aug 2023 16:01:25 -0400 Subject: code cleanup --- src/commands/open_file.rs | 13 ++++++++----- src/commands/parent_cursor_move.rs | 10 ++++++---- src/history.rs | 25 +++++++++++-------------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index c680cb7..c93f721 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -18,12 +18,15 @@ use crate::MIMETYPE_T; fn _get_options<'a>(path: &path::Path) -> Vec<&'a ProgramEntry> { let mut options: Vec<&ProgramEntry> = Vec::new(); - if let Some(file_ext) = path.extension().and_then(|ext| ext.to_str()) { - if let Some(entries) = MIMETYPE_T.app_list_for_ext(file_ext) { - options.extend(entries); - return options; - } + if let Some(entries) = path + .extension() + .and_then(|ext| ext.to_str()) + .and_then(|file_ext| MIMETYPE_T.app_list_for_ext(file_ext)) + { + options.extend(entries); + return options; } + if let Ok(file_mimetype) = get_mimetype(path) { if let Some(entry) = MIMETYPE_T.app_list_for_mimetype(file_mimetype.get_type()) { match entry.subtypes().get(file_mimetype.get_subtype()) { diff --git a/src/commands/parent_cursor_move.rs b/src/commands/parent_cursor_move.rs index b6c26fb..b19ebe3 100644 --- a/src/commands/parent_cursor_move.rs +++ b/src/commands/parent_cursor_move.rs @@ -46,10 +46,12 @@ pub fn parent_up(context: &mut AppContext, u: usize) -> JoshutoResult { } pub fn parent_down(context: &mut AppContext, u: usize) -> JoshutoResult { - let movement = match context.tab_context_ref().curr_tab_ref().parent_list_ref() { - Some(list) => list.get_index().map(|idx| idx + u), - None => None, - }; + let movement = context + .tab_context_ref() + .curr_tab_ref() + .parent_list_ref() + .and_then(|list| list.get_index().map(|idx| idx + u)); + if let Some(s) = movement { parent_cursor_move(context, s)?; } diff --git a/src/history.rs b/src/history.rs index dc70ff5..6fd0646 100644 --- a/src/history.rs +++ b/src/history.rs @@ -216,20 +216,17 @@ pub fn create_dirlist_with_history( None => 0, } }; - let visual_mode_anchor_index = match history.get(path) { - None => None, - Some(dirlist) => { - dirlist - .get_visual_mode_anchor_index() - .map(|old_visual_mode_anchor_index| { - if old_visual_mode_anchor_index < contents_len { - old_visual_mode_anchor_index - } else { - contents_len - 1 - } - }) - } - }; + let visual_mode_anchor_index = history.get(path).and_then(|dirlist| { + dirlist + .get_visual_mode_anchor_index() + .map(|old_visual_mode_anchor_index| { + if old_visual_mode_anchor_index < contents_len { + old_visual_mode_anchor_index + } else { + contents_len - 1 + } + }) + }); let metadata = JoshutoMetadata::from(path)?; let dirlist = JoshutoDirList::new( -- cgit v1.2.3