Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/gui/macro_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ impl MacroDialog {
{
let filter = self.add_filter.trim().to_lowercase();
let mut actions = if plugin.name() == "folders" {
plugin.search(&format!("f {}", self.add_filter))
plugin.search(&format!("f list {}", self.add_filter))
} else if plugin.name() == "bookmarks" {
plugin.search(&format!("bm {}", self.add_filter))
plugin.search(&format!("bm list {}", self.add_filter))
} else {
plugin.commands()
};
Expand Down
63 changes: 39 additions & 24 deletions src/plugins/folders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,33 @@ impl FoldersPlugin {
watcher,
}
}

fn list_entries(&self, filter: &str) -> Vec<Action> {
let guard = match self.data.lock() {
Ok(g) => g,
Err(_) => return Vec::new(),
};
guard
.iter()
.filter(|f| {
self.matcher.fuzzy_match(&f.label, filter).is_some()
|| self.matcher.fuzzy_match(&f.path, filter).is_some()
|| f.alias
.as_ref()
.map(|a| self.matcher.fuzzy_match(a, filter).is_some())
.unwrap_or(false)
})
.map(|f| {
let label = f.alias.clone().unwrap_or_else(|| f.label.clone());
Action {
label,
desc: f.path.clone(),
action: f.path.clone(),
args: None,
}
})
.collect()
}
}

impl Default for FoldersPlugin {
Expand Down Expand Up @@ -212,36 +239,18 @@ impl Plugin for FoldersPlugin {
.collect();
}

const LIST_PREFIX: &str = "f list";
if let Some(rest) = crate::common::strip_prefix_ci(query, LIST_PREFIX) {
return self.list_entries(rest.trim());
}

const PREFIX: &str = "f";
let rest = match crate::common::strip_prefix_ci(query, PREFIX) {
Some(r) => r,
None => return Vec::new(),
};
let filter = rest.trim();
let guard = match self.data.lock() {
Ok(g) => g,
Err(_) => return Vec::new(),
};
guard
.iter()
.filter(|f| {
self.matcher.fuzzy_match(&f.label, filter).is_some()
|| self.matcher.fuzzy_match(&f.path, filter).is_some()
|| f.alias
.as_ref()
.map(|a| self.matcher.fuzzy_match(a, filter).is_some())
.unwrap_or(false)
})
.map(|f| {
let label = f.alias.clone().unwrap_or_else(|| f.label.clone());
Action {
label,
desc: f.path.clone(),
action: f.path.clone(),
args: None,
}
})
.collect()
self.list_entries(filter)
}

fn name(&self) -> &str {
Expand All @@ -264,6 +273,12 @@ impl Plugin for FoldersPlugin {
action: "query:f ".into(),
args: None,
},
Action {
label: "f list".into(),
desc: "Folder".into(),
action: "query:f list ".into(),
args: None,
},
Action {
label: "f add".into(),
desc: "Folder".into(),
Expand Down