Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions yazi-fm/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ use std::sync::atomic::Ordering;

use anyhow::Result;
use crossterm::event::KeyEvent;
use mlua::{ObjectLike, Table, Value};
use tracing::error;
use yazi_actor::lives::Lives;
use yazi_config::keymap::Key;
use yazi_macro::{act, emit, succ};
use yazi_plugin::LUA;
use yazi_shared::event::{CmdCow, Data, Event, NEED_RENDER};
use yazi_widgets::input::InputMode;

Expand Down Expand Up @@ -58,6 +62,23 @@ impl<'a> Dispatcher<'a> {
succ!();
}

#[inline]
fn dispatch_drop(&mut self, str: String) -> Result<Data> {
let Some(size) = self.app.term.as_ref().and_then(|t| t.size().ok()) else { succ!() };

let result = Lives::scope(&self.app.core, move || {
let area = yazi_binding::elements::Rect::from(size);
let root = LUA.globals().raw_get::<Table>("Root")?.call_method::<Table>("new", area)?;
root.call_method::<Value>("drop", str.to_string())?;
Ok(())
});

if let Err(ref e) = result {
error!("{e}");
}
succ!();
}

#[inline]
fn dispatch_paste(&mut self, str: String) -> Result<Data> {
if self.app.core.input.visible {
Expand All @@ -67,6 +88,8 @@ impl<'a> Dispatcher<'a> {
} else if input.mode() == InputMode::Replace {
input.replace_str(&str)?;
}
} else {
self.dispatch_drop(str)?;
}
succ!();
}
Expand Down
2 changes: 2 additions & 0 deletions yazi-plugin/preset/components/root.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ end
function Root:move(event) end

function Root:drag(event) end

function Root:drop(data) end
Loading