diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index e52f8a7e..766a3cbf 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1385,8 +1385,7 @@ impl Component for EditorView { if let Some(position) = config.explorer.is_embed() { let area = if use_bufferline { area.clip_top(1) - } - else { + } else { area }; explorer.content.render_embed(area, surface, cx, &position); @@ -1478,8 +1477,7 @@ impl Component for EditorView { if let Some(position) = config.explorer.is_embed() { let area = if use_bufferline { area.clip_top(1) - } - else { + } else { area }; explore.content.render_embed(area, surface, cx, &position); diff --git a/helix-term/src/ui/explorer.rs b/helix-term/src/ui/explorer.rs index 17b3dcdc..80b4fb21 100644 --- a/helix-term/src/ui/explorer.rs +++ b/helix-term/src/ui/explorer.rs @@ -50,7 +50,7 @@ impl FileInfo { fn get_text(&self) -> Cow<'static, str> { match self.file_type { - FileType::Root => return format!("{}", self.path.display()).into(), + FileType::Root => format!("{}", self.path.display()).into(), FileType::File | FileType::Folder => self .path .file_name() @@ -107,14 +107,11 @@ impl TreeViewItem for FileInfo { } fn is_parent(&self) -> bool { - match self.file_type { - FileType::Folder | FileType::Root => true, - _ => false, - } + matches!(self.file_type, FileType::Folder | FileType::Root) } } -fn dir_entry_to_file_info(entry: DirEntry, path: &PathBuf) -> Option { +fn dir_entry_to_file_info(entry: DirEntry, path: &Path) -> Option { entry.metadata().ok().map(|meta| { let file_type = match meta.is_dir() { true => FileType::Folder, @@ -196,7 +193,7 @@ impl Explorer { } fn new_tree_view(root: PathBuf) -> Result> { - let root = FileInfo::root(root.clone()); + let root = FileInfo::root(root); let children = root.get_children()?; Ok(TreeView::build_tree(root, children).with_enter_fn(Self::toggle_current)) } @@ -368,7 +365,7 @@ impl Explorer { self.prompt = Some(( PromptAction::RenameFile, Prompt::new( - format!(" Rename to ").into(), + " Rename to ".into(), None, ui::completers::none, |_, _, _| {}, @@ -689,7 +686,7 @@ impl Explorer { } fn change_root_parent_folder(&mut self) -> Result<()> { - if let Some(parent) = self.state.current_root.parent().clone() { + if let Some(parent) = self.state.current_root.parent() { let path = parent.to_path_buf(); self.change_root(path) } else { @@ -725,7 +722,7 @@ impl Explorer { } std::fs::rename(&item.path, &path)?; self.tree.refresh()?; - self.reveal_file(path.into()) + self.reveal_file(path) } fn remove_folder(&mut self) -> Result<()> { @@ -752,7 +749,7 @@ fn close_documents(current_item_path: PathBuf, cx: &mut Context) -> Result<()> { .map(|p| p.starts_with(¤t_item_path)) .unwrap_or(false) { - Some(id.clone()) + Some(*id) } else { None } @@ -855,8 +852,7 @@ fn get_preview(p: impl AsRef, max_line: usize) -> Result> { .filter_map(|entry| { entry .ok() - .map(|entry| dir_entry_to_file_info(entry, &p.to_path_buf())) - .flatten() + .and_then(|entry| dir_entry_to_file_info(entry, p)) }) .take(max_line) .collect::>(); diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 12701f64..ce78e9f9 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -29,7 +29,7 @@ pub use popup::Popup; pub use prompt::{Prompt, PromptEvent}; pub use spinner::{ProgressSpinners, Spinner}; pub use text::Text; -pub use tree::{TreeViewItem, TreeOp, TreeView}; +pub use tree::{TreeOp, TreeView, TreeViewItem}; use helix_core::regex::Regex; use helix_core::regex::RegexBuilder; diff --git a/helix-term/src/ui/tree.rs b/helix-term/src/ui/tree.rs index 2997e5b3..8e8ae1f4 100644 --- a/helix-term/src/ui/tree.rs +++ b/helix-term/src/ui/tree.rs @@ -123,7 +123,7 @@ impl<'a, T> DoubleEndedIterator for TreeIter<'a, T> { impl<'a, T> ExactSizeIterator for TreeIter<'a, T> {} impl Tree { - fn open(&mut self, filter: &String) -> Result<()> { + fn open(&mut self, filter: &str) -> Result<()> { if self.item.is_parent() { self.children = self.get_filtered_children(filter)?; self.is_opened = true; @@ -136,12 +136,12 @@ impl Tree { self.children = vec![]; } - fn refresh(&mut self, filter: &String) -> Result<()> { + fn refresh(&mut self, filter: &str) -> Result<()> { if !self.is_opened { return Ok(()); } let latest_children = self.get_filtered_children(filter)?; - let filtered = std::mem::replace(&mut self.children, vec![]) + let filtered = std::mem::take(&mut self.children) .into_iter() // Remove children that does not exists in latest_children .filter(|tree| { @@ -174,7 +174,7 @@ impl Tree { Ok(()) } - fn get_filtered_children(&self, filter: &String) -> Result>> { + fn get_filtered_children(&self, filter: &str) -> Result>> { Ok(vec_to_tree( self.item .get_children()? @@ -242,7 +242,7 @@ impl Tree { &self.item } - fn get<'a>(&'a self, index: usize) -> Option<&'a Tree> { + fn get(&self, index: usize) -> Option<&Tree> { if self.index == index { Some(self) } else { @@ -261,7 +261,7 @@ impl Tree { } fn len(&self) -> usize { - (1 as usize).saturating_add(self.children.iter().map(|elem| elem.len()).sum()) + (1_usize).saturating_add(self.children.iter().map(|elem| elem.len()).sum()) } fn regenerate_index(&mut self) { @@ -373,7 +373,7 @@ impl TreeView { /// /// vec!["helix-term", "src", "ui", "tree.rs"] /// - pub fn reveal_item(&mut self, segments: Vec, filter: &String) -> Result<()> { + pub fn reveal_item(&mut self, segments: Vec, filter: &str) -> Result<()> { self.refresh_with_filter(filter)?; // Expand the tree @@ -447,7 +447,7 @@ impl TreeView { Ok(()) } - fn move_to_children(&mut self, filter: &String) -> Result<()> { + fn move_to_children(&mut self, filter: &str) -> Result<()> { let current = self.current_mut()?; if current.is_opened { self.set_selected(self.selected + 1); @@ -466,7 +466,7 @@ impl TreeView { self.refresh_with_filter(&self.filter.clone()) } - fn refresh_with_filter(&mut self, filter: &String) -> Result<()> { + fn refresh_with_filter(&mut self, filter: &str) -> Result<()> { self.tree.refresh(filter)?; self.set_selected(self.selected); Ok(()) @@ -526,7 +526,7 @@ impl TreeView { cx: &mut Context, params: &mut T::Params, selected_index: usize, - filter: &String, + filter: &str, ) -> Result<()> { let selected_item = self.get_mut(selected_index)?; if selected_item.is_opened { @@ -561,7 +561,7 @@ impl TreeView { } fn saved_view(&self) -> SavedView { - self.saved_view.clone().unwrap_or_else(|| SavedView { + self.saved_view.clone().unwrap_or(SavedView { selected: self.selected, }) } @@ -776,7 +776,7 @@ fn render_tree( } impl TreeView { - pub fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context, filter: &String) { + pub fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context, filter: &str) { let style = cx.editor.theme.get(&self.tree_symbol_style); let filter_prompt_area = area.with_height(1); @@ -847,7 +847,7 @@ impl TreeView { } #[cfg(test)] - pub fn render_to_string(&mut self, area: Rect, filter: &String) -> String { + pub fn render_to_string(&mut self, area: Rect, filter: &str) -> String { let lines = self.render_lines(area, filter); lines .into_iter() @@ -865,7 +865,7 @@ impl TreeView { .join("\n") } - fn render_lines(&mut self, area: Rect, filter: &String) -> Vec { + fn render_lines(&mut self, area: Rect, filter: &str) -> Vec { if let Some(pre_render) = self.pre_render.take() { pre_render(self, area); } @@ -995,7 +995,7 @@ impl TreeView { event: &Event, cx: &mut Context, params: &mut T::Params, - filter: &String, + filter: &str, ) -> EventResult { let key_event = match event { Event::Key(event) => event, @@ -1085,7 +1085,7 @@ impl TreeView { } key!(Esc) | ctrl!('c') => { self.filter.clear(); - self.refresh_with_filter(&"".to_string())?; + self.refresh_with_filter("")?; } _ => { if let EventResult::Consumed(_) = diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 055f1870..914159d2 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -241,10 +241,7 @@ impl ExplorerConfig { } pub fn is_overlay(&self) -> bool { - match self.position { - ExplorerPosition::Overlay => true, - _ => false, - } + matches!(self.position, ExplorerPosition::Overlay) } } @@ -257,7 +254,7 @@ impl Default for ExplorerConfig { } } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct Config { /// Padding to keep between the edge of the screen and the cursor when scrolling. Defaults to 5.