Skip to content

Commit

Permalink
WIP: refactor: send the move events after moving is successful
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikavilpas authored and sxyazi committed Apr 8, 2024
1 parent 872a6a4 commit 63b20ba
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
7 changes: 0 additions & 7 deletions yazi-core/src/manager/commands/paste.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use yazi_dds::Pubsub;
use yazi_shared::event::Cmd;

use crate::{manager::Manager, tasks::Tasks};
Expand All @@ -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 {
Expand Down
10 changes: 4 additions & 6 deletions yazi-dds/src/body/move_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand All @@ -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)?),
])?
Expand Down
8 changes: 4 additions & 4 deletions yazi-dds/src/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
2 changes: 2 additions & 0 deletions yazi-scheduler/src/file/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 63b20ba

Please sign in to comment.