mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: offset cursor shift when deleting multiple files in bulk (#2030)
This commit is contained in:
parent
ccf466d881
commit
a64e8a8b59
2 changed files with 37 additions and 30 deletions
|
|
@ -51,7 +51,10 @@ impl Folder {
|
||||||
FilesOp::IOErr(..) => self.files.update_ioerr(),
|
FilesOp::IOErr(..) => self.files.update_ioerr(),
|
||||||
|
|
||||||
FilesOp::Creating(_, files) => self.files.update_creating(files),
|
FilesOp::Creating(_, files) => self.files.update_creating(files),
|
||||||
FilesOp::Deleting(_, urns) => self.files.update_deleting(urns),
|
FilesOp::Deleting(_, urns) => {
|
||||||
|
let deleted = self.files.update_deleting(urns);
|
||||||
|
self.cursor -= deleted.into_iter().filter(|&i| i < self.cursor).count();
|
||||||
|
}
|
||||||
FilesOp::Updating(_, files) => _ = self.files.update_updating(files),
|
FilesOp::Updating(_, files) => _ = self.files.update_updating(files),
|
||||||
FilesOp::Upserting(_, files) => self.files.update_upserting(files),
|
FilesOp::Upserting(_, files) => self.files.update_upserting(files),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{collections::{HashMap, HashSet}, mem, ops::Deref};
|
use std::{collections::{HashMap, HashSet}, mem, ops::{Deref, Not}};
|
||||||
|
|
||||||
use tokio::{fs::{self, DirEntry}, select, sync::mpsc::{self, UnboundedReceiver}};
|
use tokio::{fs::{self, DirEntry}, select, sync::mpsc::{self, UnboundedReceiver}};
|
||||||
use yazi_shared::{Id, url::{Url, Urn, UrnBuf}};
|
use yazi_shared::{Id, url::{Url, Urn, UrnBuf}};
|
||||||
|
|
@ -182,19 +182,9 @@ impl Files {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub fn update_deleting(&mut self, urns: HashSet<UrnBuf>) {
|
pub fn update_deleting(&mut self, urns: HashSet<UrnBuf>) -> Vec<usize> {
|
||||||
if urns.is_empty() {
|
if urns.is_empty() {
|
||||||
return;
|
return vec![];
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! go {
|
|
||||||
($dist:expr, $src:expr, $inc:literal) => {
|
|
||||||
let len = $dist.len();
|
|
||||||
$dist.retain(|f| !$src.remove(f.urn()));
|
|
||||||
if $dist.len() != len {
|
|
||||||
self.revision += $inc;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let (mut hidden, mut items) = if let Some(filter) = &self.filter {
|
let (mut hidden, mut items) = if let Some(filter) = &self.filter {
|
||||||
|
|
@ -208,32 +198,46 @@ impl Files {
|
||||||
urns.into_iter().partition(|u| u.as_urn().is_hidden())
|
urns.into_iter().partition(|u| u.as_urn().is_hidden())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut deleted = Vec::with_capacity(items.len());
|
||||||
if !items.is_empty() {
|
if !items.is_empty() {
|
||||||
go!(self.items, items, 1);
|
let mut i = 0;
|
||||||
|
self.items.retain(|f| {
|
||||||
|
let b = items.remove(f.urn());
|
||||||
|
if b {
|
||||||
|
deleted.push(i);
|
||||||
|
}
|
||||||
|
i += 1;
|
||||||
|
!b
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if !hidden.is_empty() {
|
if !hidden.is_empty() {
|
||||||
go!(self.hidden, hidden, 0);
|
self.hidden.retain(|f| !hidden.remove(f.urn()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.revision += deleted.is_empty().not() as u64;
|
||||||
|
deleted
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub fn update_deleting(&mut self, mut urns: HashSet<UrnBuf>) {
|
pub fn update_deleting(&mut self, mut urns: HashSet<UrnBuf>) -> Vec<usize> {
|
||||||
macro_rules! go {
|
let mut deleted = Vec::with_capacity(urns.len());
|
||||||
($dist:expr, $src:expr, $inc:literal) => {
|
if !urns.is_empty() {
|
||||||
let len = $dist.len();
|
let mut i = 0;
|
||||||
$dist.retain(|f| !$src.remove(f.urn()));
|
self.items.retain(|f| {
|
||||||
if $dist.len() != len {
|
let b = urns.remove(f.urn());
|
||||||
self.revision += $inc;
|
if b {
|
||||||
|
deleted.push(i)
|
||||||
}
|
}
|
||||||
};
|
i += 1;
|
||||||
|
!b
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if !urns.is_empty() {
|
||||||
|
self.hidden.retain(|f| !urns.remove(f.urn()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !urns.is_empty() {
|
self.revision += deleted.is_empty().not() as u64;
|
||||||
go!(self.items, urns, 1);
|
deleted
|
||||||
}
|
|
||||||
if !urns.is_empty() {
|
|
||||||
go!(self.hidden, urns, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_updating(
|
pub fn update_updating(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue