Add update of selected file in explorer when switching buffers

feature/file-explorer
trivernis 1 year ago
parent cf9669f276
commit 432522e724
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1496,7 +1496,26 @@ impl Component for EditorView {
}
if let Some(explore) = self.explorer.as_mut() {
if explore.is_focus() {
let needs_update = explore.is_focus() || {
if let Some(current_document_path) = doc!(cx.editor).path().cloned() {
if let Some(current_explore_path) = explore.current_file() {
if *current_explore_path != current_document_path {
let _ = explore.reveal_file(current_document_path);
true
} else {
false
}
} else {
let _ = explore.reveal_file(current_document_path);
true
}
} else {
false
}
};
if needs_update {
let area = if use_bufferline {
area.clip_top(1)
} else {

@ -605,6 +605,11 @@ impl Explorer {
}
}
/// Returns the current file in the tree view
pub fn current_file(&self) -> Option<&PathBuf> {
self.tree.current_item().ok().map(|c| &c.path)
}
pub fn is_opened(&self) -> bool {
self.state.open
}

Loading…
Cancel
Save