feat: support mouse drop event

This commit is contained in:
Huy Hoang 2025-08-24 21:38:17 +07:00
parent c27ef58116
commit 5bde604665
No known key found for this signature in database
GPG key ID: 1B35FB52C310195E
2 changed files with 25 additions and 0 deletions

View file

@ -2,8 +2,12 @@ use std::sync::atomic::Ordering;
use anyhow::Result; use anyhow::Result;
use crossterm::event::KeyEvent; use crossterm::event::KeyEvent;
use mlua::{ObjectLike, Table, Value};
use tracing::error;
use yazi_actor::lives::Lives;
use yazi_config::keymap::Key; use yazi_config::keymap::Key;
use yazi_macro::{act, emit, succ}; use yazi_macro::{act, emit, succ};
use yazi_plugin::LUA;
use yazi_shared::event::{CmdCow, Data, Event, NEED_RENDER}; use yazi_shared::event::{CmdCow, Data, Event, NEED_RENDER};
use yazi_widgets::input::InputMode; use yazi_widgets::input::InputMode;
@ -58,6 +62,23 @@ impl<'a> Dispatcher<'a> {
succ!(); 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] #[inline]
fn dispatch_paste(&mut self, str: String) -> Result<Data> { fn dispatch_paste(&mut self, str: String) -> Result<Data> {
if self.app.core.input.visible { if self.app.core.input.visible {
@ -67,6 +88,8 @@ impl<'a> Dispatcher<'a> {
} else if input.mode() == InputMode::Replace { } else if input.mode() == InputMode::Replace {
input.replace_str(&str)?; input.replace_str(&str)?;
} }
} else {
self.dispatch_drop(str)?;
} }
succ!(); succ!();
} }

View file

@ -76,3 +76,5 @@ end
function Root:move(event) end function Root:move(event) end
function Root:drag(event) end function Root:drag(event) end
function Root:drop(data) end