mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
feat: allow filtering workspace filetree
This commit is contained in:
parent
3b45c4ddb6
commit
a99eee170d
6 changed files with 20 additions and 14 deletions
|
@ -7,8 +7,8 @@ use crate::buffer::controller::BufferController;
|
|||
|
||||
#[napi]
|
||||
impl BufferController {
|
||||
#[napi(ts_args_type = "fun: (event: TextChange) => void")]
|
||||
pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{
|
||||
#[napi(js_name = "callback", ts_args_type = "fun: (event: TextChange) => void")]
|
||||
pub fn jscallback(&self, fun: napi::JsFunction) -> napi::Result<()>{
|
||||
let tsfn : ThreadsafeFunction<crate::api::TextChange, Fatal> =
|
||||
fun.create_threadsafe_function(0,
|
||||
|ctx : ThreadSafeCallContext<crate::api::TextChange>| {
|
||||
|
|
|
@ -42,8 +42,8 @@ impl From<crate::api::Cursor> for JsCursor {
|
|||
|
||||
#[napi]
|
||||
impl CursorController {
|
||||
#[napi(ts_args_type = "fun: (event: Cursor) => void")]
|
||||
pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{
|
||||
#[napi(js_name = "callback", ts_args_type = "fun: (event: Cursor) => void")]
|
||||
pub fn jscallback(&self, fun: napi::JsFunction) -> napi::Result<()>{
|
||||
let tsfn : ThreadsafeFunction<JsCursor, ErrorStrategy::Fatal> =
|
||||
fun.create_threadsafe_function(0,
|
||||
|ctx : ThreadSafeCallContext<JsCursor>| {
|
||||
|
|
|
@ -12,8 +12,8 @@ impl Workspace {
|
|||
}
|
||||
|
||||
#[napi(js_name = "filetree")]
|
||||
pub fn js_filetree(&self) -> Vec<String> {
|
||||
self.filetree()
|
||||
pub fn js_filetree(&self, filter: Option<&str>) -> Vec<String> {
|
||||
self.filetree(filter)
|
||||
}
|
||||
|
||||
#[napi(js_name = "cursor")]
|
||||
|
|
|
@ -166,12 +166,15 @@ impl LuaUserData for CodempWorkspace {
|
|||
});
|
||||
Ok(())
|
||||
});
|
||||
|
||||
methods.add_method("filetree", |_, this, (filter,):(Option<String>,)|
|
||||
Ok(this.filetree(filter.as_deref()))
|
||||
);
|
||||
}
|
||||
|
||||
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
|
||||
fields.add_field_method_get("id", |_, this| Ok(this.id()));
|
||||
fields.add_field_method_get("cursor", |_, this| Ok(this.cursor()));
|
||||
fields.add_field_method_get("filetree", |_, this| Ok(this.filetree()));
|
||||
fields.add_field_method_get("active_buffers", |_, this| Ok(this.buffer_list()));
|
||||
// fields.add_field_method_get("users", |_, this| Ok(this.0.users())); // TODO
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ impl Workspace {
|
|||
.list_buffer_users(path.as_str())
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|e| e.id)
|
||||
.map(|e| e.id.to_string())
|
||||
.collect();
|
||||
|
||||
Ok(usrlist)
|
||||
|
@ -118,8 +118,8 @@ impl Workspace {
|
|||
}
|
||||
|
||||
#[pyo3(name = "filetree")]
|
||||
fn pyfiletree(&self) -> Vec<String> {
|
||||
self.filetree()
|
||||
fn pyfiletree(&self, filter: Option<&str>) -> Vec<String> {
|
||||
self.filetree(filter)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -332,8 +332,11 @@ impl Workspace {
|
|||
|
||||
/// get the currently cached "filetree"
|
||||
// #[cfg_attr(feature = "js", napi)] // https://github.com/napi-rs/napi-rs/issues/1120
|
||||
pub fn filetree(&self) -> Vec<String> {
|
||||
self.0.filetree.iter().map(|f| f.clone()).collect()
|
||||
pub fn filetree(&self, filter: Option<&str>) -> Vec<String> {
|
||||
self.0.filetree.iter()
|
||||
.filter(|f| filter.map_or(true, |flt| f.starts_with(flt)))
|
||||
.map(|f| f.clone())
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue