Skip to content

Commit 63b20ba

Browse files
mikavilpassxyazi
authored andcommitted
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.
1 parent 872a6a4 commit 63b20ba

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

yazi-core/src/manager/commands/paste.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use yazi_dds::Pubsub;
21
use yazi_shared::event::Cmd;
32

43
use crate::{manager::Manager, tasks::Tasks};
@@ -22,12 +21,6 @@ impl Manager {
2221
if self.yanked.cut {
2322
tasks.file_cut(&src, dest, opt.force);
2423

25-
src.iter().for_each(|source_file| {
26-
if let Some(name) = source_file.file_name().map(|s| dest.join(s)) {
27-
Pubsub::pub_from_move(self.tabs.cursor, source_file, &name);
28-
}
29-
});
30-
3124
self.tabs.iter_mut().for_each(|t| _ = t.selected.remove_many(&src, false));
3225
self.unyank(());
3326
} else {

yazi-dds/src/body/move_.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@ use super::Body;
88

99
#[derive(Debug, Serialize, Deserialize)]
1010
pub struct BodyMove<'a> {
11-
pub tab: usize,
1211
pub from: Cow<'a, Url>,
1312
pub to: Cow<'a, Url>,
1413
}
1514

1615
impl<'a> BodyMove<'a> {
1716
#[inline]
18-
pub fn borrowed(tab: usize, from: &'a Url, to: &'a Url) -> Body<'a> {
19-
Self { tab, from: Cow::Borrowed(from), to: Cow::Borrowed(to) }.into()
17+
pub fn borrowed(from: &'a Url, to: &'a Url) -> Body<'a> {
18+
Self { from: Cow::Borrowed(from), to: Cow::Borrowed(to) }.into()
2019
}
2120
}
2221

2322
impl BodyMove<'static> {
2423
#[inline]
25-
pub fn dummy(tab: usize, from: &Url, to: &Url) -> Body<'static> {
26-
Self { tab, from: Cow::Owned(from.clone()), to: Cow::Owned(to.clone()) }.into()
24+
pub fn dummy(from: &Url, to: &Url) -> Body<'static> {
25+
Self { from: Cow::Owned(from.clone()), to: Cow::Owned(to.clone()) }.into()
2726
}
2827
}
2928

@@ -37,7 +36,6 @@ impl IntoLua<'_> for BodyMove<'static> {
3736
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> {
3837
lua
3938
.create_table_from([
40-
("tab", self.tab.into_lua(lua)?),
4139
("from", lua.create_any_userdata(self.from.into_owned())?.into_lua(lua)?),
4240
("to", lua.create_any_userdata(self.to.into_owned())?.into_lua(lua)?),
4341
])?

yazi-dds/src/pubsub.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ impl Pubsub {
150150
}
151151
}
152152

153-
pub fn pub_from_move(tab: usize, from: &Url, to: &Url) {
153+
pub fn pub_from_move(from: &Url, to: &Url) {
154154
if LOCAL.read().contains_key("move") {
155-
Self::pub_(BodyMove::dummy(tab, from, to));
155+
Self::pub_(BodyMove::dummy(from, to));
156156
}
157157
if PEERS.read().values().any(|p| p.able("move")) {
158-
Client::push(BodyMove::borrowed(tab, from, to));
158+
Client::push(BodyMove::borrowed(from, to));
159159
}
160160
if BOOT.local_events.contains("move") {
161-
BodyMove::borrowed(tab, from, to).with_receiver(*ID).flush();
161+
BodyMove::borrowed(from, to).with_receiver(*ID).flush();
162162
}
163163
}
164164
}

yazi-scheduler/src/file/file.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use futures::{future::BoxFuture, FutureExt};
55
use tokio::{fs, io::{self, ErrorKind::{AlreadyExists, NotFound}}, sync::mpsc};
66
use tracing::warn;
77
use yazi_config::TASKS;
8+
use yazi_dds::Pubsub;
89
use yazi_shared::fs::{accessible, calculate_size, copy_with_progress, path_relative_to, Url};
910

1011
use super::{FileOp, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash};
@@ -37,6 +38,7 @@ impl File {
3738
Ok(0) => {
3839
if task.cut {
3940
fs::remove_file(&task.from).await.ok();
41+
Pubsub::pub_from_move(&task.from, &task.to);
4042
}
4143
break;
4244
}

0 commit comments

Comments
 (0)