mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Use Url instead of PathBuf
This commit is contained in:
parent
cd71fccc9a
commit
76711cb9a9
1 changed files with 15 additions and 23 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
use std::{collections::{BTreeSet, HashMap}, path::PathBuf};
|
use std::collections::{BTreeSet, HashMap};
|
||||||
|
|
||||||
use yazi_shared::fs::Url;
|
use yazi_shared::fs::Url;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Selected {
|
pub struct Selected {
|
||||||
inner: BTreeSet<Url>,
|
inner: BTreeSet<Url>,
|
||||||
parents: HashMap<PathBuf, usize>,
|
parents: HashMap<Url, usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Selected {
|
impl Selected {
|
||||||
|
|
@ -18,29 +18,23 @@ impl Selected {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let url_buf = urls[0].to_path_buf();
|
let mut current_path = urls[0].clone();
|
||||||
|
while let Some(parent) = current_path.parent_url() {
|
||||||
let mut current_path = url_buf.clone();
|
if self.inner.contains(&parent) {
|
||||||
while let Some(parent) = current_path.parent() {
|
|
||||||
if self.inner.contains(&Url::from(parent)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
current_path = parent.to_path_buf();
|
current_path = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.parents.contains_key(&url_buf) {
|
if self.parents.contains_key(urls[0]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut current_path = url_buf.clone();
|
let mut current_path = urls[0].clone();
|
||||||
let len_of_urls = urls.len();
|
let len_of_urls = urls.len();
|
||||||
loop {
|
while let Some(parent) = current_path.parent_url() {
|
||||||
current_path = match current_path.parent() {
|
current_path = parent;
|
||||||
Some(parent) => parent.to_path_buf(),
|
*self.parents.entry(current_path.clone()).or_insert(0) += len_of_urls;
|
||||||
None => break,
|
|
||||||
};
|
|
||||||
let counter = self.parents.entry(current_path.clone()).or_insert(0);
|
|
||||||
*counter += len_of_urls;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.inner.extend(urls.iter().cloned().cloned());
|
self.inner.extend(urls.iter().cloned().cloned());
|
||||||
|
|
@ -52,12 +46,10 @@ impl Selected {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut current_path = url.to_path_buf();
|
let mut current_path = url.clone();
|
||||||
loop {
|
while let Some(parent) = current_path.parent_url() {
|
||||||
current_path = match current_path.parent() {
|
current_path = parent;
|
||||||
Some(parent) => parent.to_path_buf(),
|
|
||||||
None => break,
|
|
||||||
};
|
|
||||||
let counter = self.parents.entry(current_path.clone()).or_insert(0);
|
let counter = self.parents.entry(current_path.clone()).or_insert(0);
|
||||||
*counter -= 1;
|
*counter -= 1;
|
||||||
if *counter == 0 {
|
if *counter == 0 {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue