diff --git a/README.md b/README.md index 024db631..56e7d4f2 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,13 @@ And others I forgot about... + +# Applied Changes + +- Changed opening the window popup from `ctrl + w` to `ctrl + v` +- Added an auto select for files in the tree explorer when jumping through opened buffers +- Changed some default settings (enabling bufferline, indent guides, the embedded explorer, cursor modes etc.) + - - - [![Build status](https://github.com/helix-editor/helix/actions/workflows/build.yml/badge.svg)](https://github.com/helix-editor/helix/actions) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index fbab360c..b94e01ad 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1370,6 +1370,11 @@ impl Component for EditorView { if let Some(explore) = self.explorer.as_mut() { if !explore.content.is_focus() && config.explorer.is_embed() { + let current_doc = view!(cx.editor).doc; + let current_doc = cx.editor.document(current_doc).unwrap(); + if let Some(path) = current_doc.path() { + explore.content.set_selection(&path); + } explore.content.render(area, surface, cx); } } diff --git a/helix-term/src/ui/explore.rs b/helix-term/src/ui/explore.rs index 951a2ebc..929cccf4 100644 --- a/helix-term/src/ui/explore.rs +++ b/helix-term/src/ui/explore.rs @@ -321,6 +321,16 @@ impl Explorer { }) } + pub fn set_selection(&mut self, path: &Path) { + let info = if path.is_file() { + FileInfo::new(path.into(), FileType::File) + } else { + FileInfo::new(path.into(), FileType::Dir) + }; + self.tree.select(&info); + self.tree.save_view(); + } + pub fn new_explorer_recursion() -> Result { let current_root = std::env::current_dir().unwrap_or_else(|_| "./".into()); let parent = FileInfo::parent(¤t_root); diff --git a/helix-term/src/ui/tree.rs b/helix-term/src/ui/tree.rs index 1a3ec01d..4379bbac 100644 --- a/helix-term/src/ui/tree.rs +++ b/helix-term/src/ui/tree.rs @@ -431,6 +431,19 @@ impl Tree { self.items[self.selected].item = item; } + pub fn select(&mut self, select_item: &T) { + let selected = self + .items + .iter() + .enumerate() + .filter(|(_, i)| i.item.cmp(select_item) == Ordering::Equal) + .next(); + if let Some((idx, _)) = selected { + self.selected = idx; + self.row = idx; + } + } + pub fn insert_current_level(&mut self, item: T) { let current = self.current(); let level = current.level;