yazi/yazi-core/src/mgr/snap.rs
三咲雅 misaki masa aba0b5ad01
feat: trash bin
2026-07-22 02:20:54 +08:00

43 lines
1.1 KiB
Rust

use yazi_fs::{Splatable, file::File};
use crate::{mgr::Mgr, tab::TabSnap};
pub struct MgrSnap {
tab: usize,
tabs: Vec<TabSnap>,
yanked: Vec<File>,
}
impl From<&Mgr> for MgrSnap {
fn from(value: &Mgr) -> Self {
Self {
tab: value.tabs.cursor,
tabs: value.tabs.iter().map(Into::into).collect(),
yanked: value.yanked.files().cloned().collect(),
}
}
}
impl Splatable for MgrSnap {
fn tab(&self) -> usize { self.tab + 1 }
fn selected(&self, tab: usize, mut idx: Option<usize>) -> impl Iterator<Item = &File> {
idx = idx.and_then(|i| i.checked_sub(1));
tab
.checked_sub(1)
.and_then(|tab| self.tabs.get(tab))
.map_or_else(|| &[][..], |s| &s.selected)
.iter()
.skip(idx.unwrap_or(0))
.take(if idx.is_some() { 1 } else { usize::MAX })
}
fn hovered(&self, tab: usize) -> Option<&File> {
tab.checked_sub(1).and_then(|tab| self.tabs.get(tab)).and_then(|tab| tab.hovered.as_ref())
}
fn yanked(&self, mut idx: Option<usize>) -> impl Iterator<Item = &File> {
idx = idx.and_then(|i| i.checked_sub(1));
self.yanked.iter().skip(idx.unwrap_or(0)).take(if idx.is_some() { 1 } else { usize::MAX })
}
}