mirror of
https://github.com/sxyazi/yazi.git
synced 2026-05-13 08:16:40 +00:00
fix: didn't reset previous Cha when loading directories in chunks (#2366)
This commit is contained in:
parent
4465101089
commit
f75194b7cf
4 changed files with 18 additions and 12 deletions
|
|
@ -64,7 +64,7 @@ impl Tab {
|
|||
})
|
||||
}?;
|
||||
|
||||
let rx = UnboundedReceiverStream::new(rx).chunks_timeout(1000, Duration::from_millis(300));
|
||||
let rx = UnboundedReceiverStream::new(rx).chunks_timeout(5000, Duration::from_millis(500));
|
||||
pin!(rx);
|
||||
|
||||
let ((), ticket) = (TabProxy::cd(&cwd), FilesOp::prepare(&cwd));
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ impl Folder {
|
|||
(self.cha, self.stage) = (cha, FolderStage::Loaded);
|
||||
}
|
||||
FilesOp::Part(_, ref files, _) if files.is_empty() => {
|
||||
self.stage = FolderStage::Loading;
|
||||
(self.cha, self.stage) = (Cha::dummy(), FolderStage::Loading);
|
||||
}
|
||||
FilesOp::Part(_, _, ticket) if ticket == self.files.ticket() => {
|
||||
self.stage = FolderStage::Loading;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::{borrow::Cow, ops::Not, time::Duration};
|
||||
use std::{borrow::Cow, time::Duration};
|
||||
|
||||
use tokio::{pin, task::JoinHandle};
|
||||
use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream};
|
||||
|
|
@ -40,24 +40,30 @@ impl Preview {
|
|||
}
|
||||
|
||||
pub fn go_folder(&mut self, file: File, dir: Option<Cha>, force: bool) {
|
||||
let cwd = self.same_file(&file, MIME_DIR).not().then(|| file.url_owned());
|
||||
self.go(file, Cow::Borrowed(MIME_DIR), force);
|
||||
let same = self.same_file(&file, MIME_DIR);
|
||||
let (wd, cha) = (file.url_owned(), file.cha);
|
||||
|
||||
let Some(cwd) = cwd else { return };
|
||||
self.go(file, Cow::Borrowed(MIME_DIR), force);
|
||||
if same {
|
||||
return;
|
||||
}
|
||||
|
||||
self.lock =
|
||||
Some(PreviewLock { url: wd.clone(), cha, mime: MIME_DIR.to_owned(), ..Default::default() });
|
||||
self.folder_loader.take().map(|h| h.abort());
|
||||
self.folder_loader = Some(tokio::spawn(async move {
|
||||
let Some(new) = Files::assert_stale(&cwd, dir.unwrap_or(Cha::dummy())).await else { return };
|
||||
let Ok(rx) = Files::from_dir(&cwd).await else { return };
|
||||
let Some(new) = Files::assert_stale(&wd, dir.unwrap_or(Cha::dummy())).await else { return };
|
||||
let Ok(rx) = Files::from_dir(&wd).await else { return };
|
||||
|
||||
let stream =
|
||||
UnboundedReceiverStream::new(rx).chunks_timeout(50000, Duration::from_millis(500));
|
||||
pin!(stream);
|
||||
|
||||
let ticket = FilesOp::prepare(&cwd);
|
||||
let ticket = FilesOp::prepare(&wd);
|
||||
while let Some(chunk) = stream.next().await {
|
||||
FilesOp::Part(cwd.clone(), chunk, ticket).emit();
|
||||
FilesOp::Part(wd.clone(), chunk, ticket).emit();
|
||||
}
|
||||
FilesOp::Done(cwd, new, ticket).emit();
|
||||
FilesOp::Done(wd, new, ticket).emit();
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use yazi_shared::{Layer, errors::PeekError, event::Cmd};
|
|||
use super::Utils;
|
||||
use crate::{elements::{Area, Rect, Renderable, Text, WRAP, WRAP_NO}, external::Highlighter, file::FileRef};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct PreviewLock {
|
||||
pub url: yazi_shared::url::Url,
|
||||
pub cha: yazi_fs::Cha,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue