feat!: Only return selected when hover is selected

With the cross-directory selection feature, it can be very unexpected
to select items in a parent directory, then go into a child directory
to attempt to open a file, but instead of opening the hovered file,
the selected items are opened instead.

This is especially obvious when using the smart-enter plugin that
combines the enter and open command together.

For the most part, users are most likely going to be hovering over a
selected item if they want to operate on the items that they have
selected, so this change will likely result in a net improvement in
user experience.
This commit is contained in:
hankertrix 2024-03-13 14:02:30 +08:00
parent 457c2a5c06
commit 15b2556b56

View file

@ -51,8 +51,11 @@ impl From<&Url> for Tab {
impl Tab {
// --- Current
pub fn selected_or_hovered(&self) -> Vec<&Url> {
let hovered = self.current.hovered().map(|h| vec![&h.url]).unwrap_or_default();
if self.selected.is_empty() {
self.current.hovered().map(|h| vec![&h.url]).unwrap_or_default()
hovered
} else if !self.selected.contains(hovered[0]) {
hovered
} else {
self.selected.iter().collect()
}