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]
|
#[napi]
|
||||||
impl BufferController {
|
impl BufferController {
|
||||||
#[napi(ts_args_type = "fun: (event: TextChange) => void")]
|
#[napi(js_name = "callback", ts_args_type = "fun: (event: TextChange) => void")]
|
||||||
pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{
|
pub fn jscallback(&self, fun: napi::JsFunction) -> napi::Result<()>{
|
||||||
let tsfn : ThreadsafeFunction<crate::api::TextChange, Fatal> =
|
let tsfn : ThreadsafeFunction<crate::api::TextChange, Fatal> =
|
||||||
fun.create_threadsafe_function(0,
|
fun.create_threadsafe_function(0,
|
||||||
|ctx : ThreadSafeCallContext<crate::api::TextChange>| {
|
|ctx : ThreadSafeCallContext<crate::api::TextChange>| {
|
||||||
|
|
|
@ -42,8 +42,8 @@ impl From<crate::api::Cursor> for JsCursor {
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
impl CursorController {
|
impl CursorController {
|
||||||
#[napi(ts_args_type = "fun: (event: Cursor) => void")]
|
#[napi(js_name = "callback", ts_args_type = "fun: (event: Cursor) => void")]
|
||||||
pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{
|
pub fn jscallback(&self, fun: napi::JsFunction) -> napi::Result<()>{
|
||||||
let tsfn : ThreadsafeFunction<JsCursor, ErrorStrategy::Fatal> =
|
let tsfn : ThreadsafeFunction<JsCursor, ErrorStrategy::Fatal> =
|
||||||
fun.create_threadsafe_function(0,
|
fun.create_threadsafe_function(0,
|
||||||
|ctx : ThreadSafeCallContext<JsCursor>| {
|
|ctx : ThreadSafeCallContext<JsCursor>| {
|
||||||
|
|
|
@ -12,8 +12,8 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi(js_name = "filetree")]
|
#[napi(js_name = "filetree")]
|
||||||
pub fn js_filetree(&self) -> Vec<String> {
|
pub fn js_filetree(&self, filter: Option<&str>) -> Vec<String> {
|
||||||
self.filetree()
|
self.filetree(filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi(js_name = "cursor")]
|
#[napi(js_name = "cursor")]
|
||||||
|
|
|
@ -166,12 +166,15 @@ impl LuaUserData for CodempWorkspace {
|
||||||
});
|
});
|
||||||
Ok(())
|
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) {
|
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("id", |_, this| Ok(this.id()));
|
||||||
fields.add_field_method_get("cursor", |_, this| Ok(this.cursor()));
|
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("active_buffers", |_, this| Ok(this.buffer_list()));
|
||||||
// fields.add_field_method_get("users", |_, this| Ok(this.0.users())); // TODO
|
// fields.add_field_method_get("users", |_, this| Ok(this.0.users())); // TODO
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ impl Workspace {
|
||||||
.list_buffer_users(path.as_str())
|
.list_buffer_users(path.as_str())
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|e| e.id)
|
.map(|e| e.id.to_string())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(usrlist)
|
Ok(usrlist)
|
||||||
|
@ -118,8 +118,8 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyo3(name = "filetree")]
|
#[pyo3(name = "filetree")]
|
||||||
fn pyfiletree(&self) -> Vec<String> {
|
fn pyfiletree(&self, filter: Option<&str>) -> Vec<String> {
|
||||||
self.filetree()
|
self.filetree(filter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -332,8 +332,11 @@ impl Workspace {
|
||||||
|
|
||||||
/// get the currently cached "filetree"
|
/// get the currently cached "filetree"
|
||||||
// #[cfg_attr(feature = "js", napi)] // https://github.com/napi-rs/napi-rs/issues/1120
|
// #[cfg_attr(feature = "js", napi)] // https://github.com/napi-rs/napi-rs/issues/1120
|
||||||
pub fn filetree(&self) -> Vec<String> {
|
pub fn filetree(&self, filter: Option<&str>) -> Vec<String> {
|
||||||
self.0.filetree.iter().map(|f| f.clone()).collect()
|
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