Add auto-select of tree explorer nodes when jumping between buffers

change-detection
trivernis 2 years ago
parent dbebd26661
commit 423435d12a
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -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)

@ -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);
}
}

@ -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<Self> {
let current_root = std::env::current_dir().unwrap_or_else(|_| "./".into());
let parent = FileInfo::parent(&current_root);

@ -431,6 +431,19 @@ impl<T: TreeItem> Tree<T> {
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;

Loading…
Cancel
Save