mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
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:
parent
872a6a4469
commit
63b20ba2cb
4 changed files with 10 additions and 17 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
use yazi_dds::Pubsub;
|
|
||||||
use yazi_shared::event::Cmd;
|
use yazi_shared::event::Cmd;
|
||||||
|
|
||||||
use crate::{manager::Manager, tasks::Tasks};
|
use crate::{manager::Manager, tasks::Tasks};
|
||||||
|
|
@ -22,12 +21,6 @@ impl Manager {
|
||||||
if self.yanked.cut {
|
if self.yanked.cut {
|
||||||
tasks.file_cut(&src, dest, opt.force);
|
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.tabs.iter_mut().for_each(|t| _ = t.selected.remove_many(&src, false));
|
||||||
self.unyank(());
|
self.unyank(());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -8,22 +8,21 @@ use super::Body;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct BodyMove<'a> {
|
pub struct BodyMove<'a> {
|
||||||
pub tab: usize,
|
|
||||||
pub from: Cow<'a, Url>,
|
pub from: Cow<'a, Url>,
|
||||||
pub to: Cow<'a, Url>,
|
pub to: Cow<'a, Url>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> BodyMove<'a> {
|
impl<'a> BodyMove<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn borrowed(tab: usize, from: &'a Url, to: &'a Url) -> Body<'a> {
|
pub fn borrowed(from: &'a Url, to: &'a Url) -> Body<'a> {
|
||||||
Self { tab, from: Cow::Borrowed(from), to: Cow::Borrowed(to) }.into()
|
Self { from: Cow::Borrowed(from), to: Cow::Borrowed(to) }.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BodyMove<'static> {
|
impl BodyMove<'static> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn dummy(tab: usize, from: &Url, to: &Url) -> Body<'static> {
|
pub fn dummy(from: &Url, to: &Url) -> Body<'static> {
|
||||||
Self { tab, from: Cow::Owned(from.clone()), to: Cow::Owned(to.clone()) }.into()
|
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> {
|
fn into_lua(self, lua: &Lua) -> mlua::Result<Value> {
|
||||||
lua
|
lua
|
||||||
.create_table_from([
|
.create_table_from([
|
||||||
("tab", self.tab.into_lua(lua)?),
|
|
||||||
("from", lua.create_any_userdata(self.from.into_owned())?.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)?),
|
("to", lua.create_any_userdata(self.to.into_owned())?.into_lua(lua)?),
|
||||||
])?
|
])?
|
||||||
|
|
|
||||||
|
|
@ -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") {
|
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")) {
|
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") {
|
if BOOT.local_events.contains("move") {
|
||||||
BodyMove::borrowed(tab, from, to).with_receiver(*ID).flush();
|
BodyMove::borrowed(from, to).with_receiver(*ID).flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use futures::{future::BoxFuture, FutureExt};
|
||||||
use tokio::{fs, io::{self, ErrorKind::{AlreadyExists, NotFound}}, sync::mpsc};
|
use tokio::{fs, io::{self, ErrorKind::{AlreadyExists, NotFound}}, sync::mpsc};
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
use yazi_config::TASKS;
|
use yazi_config::TASKS;
|
||||||
|
use yazi_dds::Pubsub;
|
||||||
use yazi_shared::fs::{accessible, calculate_size, copy_with_progress, path_relative_to, Url};
|
use yazi_shared::fs::{accessible, calculate_size, copy_with_progress, path_relative_to, Url};
|
||||||
|
|
||||||
use super::{FileOp, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash};
|
use super::{FileOp, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash};
|
||||||
|
|
@ -37,6 +38,7 @@ impl File {
|
||||||
Ok(0) => {
|
Ok(0) => {
|
||||||
if task.cut {
|
if task.cut {
|
||||||
fs::remove_file(&task.from).await.ok();
|
fs::remove_file(&task.from).await.ok();
|
||||||
|
Pubsub::pub_from_move(&task.from, &task.to);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue