mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: support mouse drop event
This commit is contained in:
parent
c27ef58116
commit
5bde604665
2 changed files with 25 additions and 0 deletions
|
|
@ -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;
|
||||
|
||||
|
|
@ -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 {
|
||||
|
|
@ -67,6 +88,8 @@ impl<'a> Dispatcher<'a> {
|
|||
} else if input.mode() == InputMode::Replace {
|
||||
input.replace_str(&str)?;
|
||||
}
|
||||
} else {
|
||||
self.dispatch_drop(str)?;
|
||||
}
|
||||
succ!();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,3 +76,5 @@ end
|
|||
function Root:move(event) end
|
||||
|
||||
function Root:drag(event) end
|
||||
|
||||
function Root:drop(data) end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue