summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2023-08-12 16:01:25 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2023-08-12 16:01:25 -0400
commite6f0d5ce01a296715d0d52755a71068a88a8bf1f (patch)
tree5a58e6977e191c47dd2c2b3286e3a9cdfd1f12e0
parent541f16850e33145ff657211e43a12f2327f188a6 (diff)
code cleanup
-rw-r--r--src/commands/open_file.rs13
-rw-r--r--src/commands/parent_cursor_move.rs10
-rw-r--r--src/history.rs25
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(