-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose selected/yanked files as API
- Loading branch information
Showing
27 changed files
with
258 additions
and
130 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use std::{collections::HashSet, ops::Deref}; | ||
|
||
use yazi_shared::fs::Url; | ||
|
||
#[derive(Default)] | ||
pub struct Yanked { | ||
pub cut: bool, | ||
pub(super) urls: HashSet<Url>, | ||
} | ||
|
||
impl Deref for Yanked { | ||
type Target = HashSet<Url>; | ||
|
||
fn deref(&self) -> &Self::Target { &self.urls } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::{collections::{btree_set, BTreeSet}, ops::Deref}; | ||
|
||
use mlua::{AnyUserData, Lua, MetaMethod, UserDataMethods, UserDataRefMut}; | ||
use yazi_plugin::{bindings::Cast, url::Url}; | ||
|
||
use super::SCOPE; | ||
|
||
#[derive(Clone, Copy)] | ||
pub(super) struct Selected { | ||
inner: *const BTreeSet<yazi_shared::fs::Url>, | ||
} | ||
|
||
impl Deref for Selected { | ||
type Target = BTreeSet<yazi_shared::fs::Url>; | ||
|
||
fn deref(&self) -> &Self::Target { self.inner() } | ||
} | ||
|
||
impl Selected { | ||
#[inline] | ||
pub(crate) fn make(inner: &BTreeSet<yazi_shared::fs::Url>) -> mlua::Result<AnyUserData<'static>> { | ||
SCOPE.create_any_userdata(Self { inner }) | ||
} | ||
|
||
pub(super) fn register(lua: &Lua) -> mlua::Result<()> { | ||
lua.register_userdata_type::<Self>(|reg| { | ||
reg.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.len())); | ||
|
||
reg.add_meta_method(MetaMethod::Pairs, |lua, me, ()| { | ||
let iter = lua.create_function(|lua, mut iter: UserDataRefMut<SelectedIter>| { | ||
Ok(if let Some(url) = iter.0.next() { Some(Url::cast(lua, url.clone())?) } else { None }) | ||
})?; | ||
|
||
Ok((iter, SelectedIter::make(me.inner()))) | ||
}); | ||
})?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[inline] | ||
fn inner(&self) -> &'static BTreeSet<yazi_shared::fs::Url> { unsafe { &*self.inner } } | ||
} | ||
|
||
struct SelectedIter(btree_set::Iter<'static, yazi_shared::fs::Url>); | ||
|
||
impl SelectedIter { | ||
#[inline] | ||
fn make(selected: &'static BTreeSet<yazi_shared::fs::Url>) -> mlua::Result<AnyUserData<'static>> { | ||
SCOPE.create_any_userdata(Self(selected.iter())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use mlua::{Lua, MetaMethod, UserDataFields, UserDataMethods}; | ||
|
||
pub(super) struct Yanked; | ||
|
||
impl Yanked { | ||
pub(super) fn register(lua: &Lua) -> mlua::Result<()> { | ||
lua.register_userdata_type::<yazi_core::manager::Yanked>(|reg| { | ||
reg.add_field_method_get("is_cut", |_, me| Ok(me.cut)); | ||
|
||
reg.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.len())); | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.