WIP: refactor: send the move events after moving is successful

NOTE: this removes the "tab" key from the event, as the tab is not
currently passed to the scheduler and it seemed like a bigger change to
do right now.
This commit is contained in:
Mika Vilpas 2024-04-06 21:46:40 +03:00 committed by sxyazi
parent 872a6a4469
commit 63b20ba2cb
No known key found for this signature in database
4 changed files with 10 additions and 17 deletions

View file

@ -1,4 +1,3 @@
use yazi_dds::Pubsub;
use yazi_shared::event::Cmd;
use crate::{manager::Manager, tasks::Tasks};
@ -22,12 +21,6 @@ impl Manager {
if self.yanked.cut {
tasks.file_cut(&src, dest, opt.force);
src.iter().for_each(|source_file| {
if let Some(name) = source_file.file_name().map(|s| dest.join(s)) {
Pubsub::pub_from_move(self.tabs.cursor, source_file, &name);
}
});
self.tabs.iter_mut().for_each(|t| _ = t.selected.remove_many(&src, false));
self.unyank(());
} else {

View file

@ -8,22 +8,21 @@ use super::Body;
#[derive(Debug, Serialize, Deserialize)]
pub struct BodyMove<'a> {
pub tab: usize,
pub from: Cow<'a, Url>,
pub to: Cow<'a, Url>,
}
impl<'a> BodyMove<'a> {
#[inline]
pub fn borrowed(tab: usize, from: &'a Url, to: &'a Url) -> Body<'a> {
Self { tab, from: Cow::Borrowed(from), to: Cow::Borrowed(to) }.into()
pub fn borrowed(from: &'a Url, to: &'a Url) -> Body<'a> {
Self { from: Cow::Borrowed(from), to: Cow::Borrowed(to) }.into()
}
}
impl BodyMove<'static> {
#[inline]
pub fn dummy(tab: usize, from: &Url, to: &Url) -> Body<'static> {
Self { tab, from: Cow::Owned(from.clone()), to: Cow::Owned(to.clone()) }.into()
pub fn dummy(from: &Url, to: &Url) -> Body<'static> {
Self { from: Cow::Owned(from.clone()), to: Cow::Owned(to.clone()) }.into()
}
}
@ -37,7 +36,6 @@ impl IntoLua<'_> for BodyMove<'static> {
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> {
lua
.create_table_from([
("tab", self.tab.into_lua(lua)?),
("from", lua.create_any_userdata(self.from.into_owned())?.into_lua(lua)?),
("to", lua.create_any_userdata(self.to.into_owned())?.into_lua(lua)?),
])?

View file

@ -150,15 +150,15 @@ impl Pubsub {
}
}
pub fn pub_from_move(tab: usize, from: &Url, to: &Url) {
pub fn pub_from_move(from: &Url, to: &Url) {
if LOCAL.read().contains_key("move") {
Self::pub_(BodyMove::dummy(tab, from, to));
Self::pub_(BodyMove::dummy(from, to));
}
if PEERS.read().values().any(|p| p.able("move")) {
Client::push(BodyMove::borrowed(tab, from, to));
Client::push(BodyMove::borrowed(from, to));
}
if BOOT.local_events.contains("move") {
BodyMove::borrowed(tab, from, to).with_receiver(*ID).flush();
BodyMove::borrowed(from, to).with_receiver(*ID).flush();
}
}
}

View file

@ -5,6 +5,7 @@ use futures::{future::BoxFuture, FutureExt};
use tokio::{fs, io::{self, ErrorKind::{AlreadyExists, NotFound}}, sync::mpsc};
use tracing::warn;
use yazi_config::TASKS;
use yazi_dds::Pubsub;
use yazi_shared::fs::{accessible, calculate_size, copy_with_progress, path_relative_to, Url};
use super::{FileOp, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash};
@ -37,6 +38,7 @@ impl File {
Ok(0) => {
if task.cut {
fs::remove_file(&task.from).await.ok();
Pubsub::pub_from_move(&task.from, &task.to);
}
break;
}