Skip to content

Commit 0e3cf5d

Browse files
authored
Merge pull request #657 from multiplex55/codex/update-macro-step-selection-for-bookmarks-and-folders
Use list queries for folders/bookmarks in macro step selection
2 parents c3fcb47 + fcde08f commit 0e3cf5d

2 files changed

Lines changed: 41 additions & 26 deletions

File tree

src/gui/macro_dialog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ impl MacroDialog {
326326
{
327327
let filter = self.add_filter.trim().to_lowercase();
328328
let mut actions = if plugin.name() == "folders" {
329-
plugin.search(&format!("f {}", self.add_filter))
329+
plugin.search(&format!("f list {}", self.add_filter))
330330
} else if plugin.name() == "bookmarks" {
331-
plugin.search(&format!("bm {}", self.add_filter))
331+
plugin.search(&format!("bm list {}", self.add_filter))
332332
} else {
333333
plugin.commands()
334334
};

src/plugins/folders.rs

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,33 @@ impl FoldersPlugin {
163163
watcher,
164164
}
165165
}
166+
167+
fn list_entries(&self, filter: &str) -> Vec<Action> {
168+
let guard = match self.data.lock() {
169+
Ok(g) => g,
170+
Err(_) => return Vec::new(),
171+
};
172+
guard
173+
.iter()
174+
.filter(|f| {
175+
self.matcher.fuzzy_match(&f.label, filter).is_some()
176+
|| self.matcher.fuzzy_match(&f.path, filter).is_some()
177+
|| f.alias
178+
.as_ref()
179+
.map(|a| self.matcher.fuzzy_match(a, filter).is_some())
180+
.unwrap_or(false)
181+
})
182+
.map(|f| {
183+
let label = f.alias.clone().unwrap_or_else(|| f.label.clone());
184+
Action {
185+
label,
186+
desc: f.path.clone(),
187+
action: f.path.clone(),
188+
args: None,
189+
}
190+
})
191+
.collect()
192+
}
166193
}
167194

168195
impl Default for FoldersPlugin {
@@ -212,36 +239,18 @@ impl Plugin for FoldersPlugin {
212239
.collect();
213240
}
214241

242+
const LIST_PREFIX: &str = "f list";
243+
if let Some(rest) = crate::common::strip_prefix_ci(query, LIST_PREFIX) {
244+
return self.list_entries(rest.trim());
245+
}
246+
215247
const PREFIX: &str = "f";
216248
let rest = match crate::common::strip_prefix_ci(query, PREFIX) {
217249
Some(r) => r,
218250
None => return Vec::new(),
219251
};
220252
let filter = rest.trim();
221-
let guard = match self.data.lock() {
222-
Ok(g) => g,
223-
Err(_) => return Vec::new(),
224-
};
225-
guard
226-
.iter()
227-
.filter(|f| {
228-
self.matcher.fuzzy_match(&f.label, filter).is_some()
229-
|| self.matcher.fuzzy_match(&f.path, filter).is_some()
230-
|| f.alias
231-
.as_ref()
232-
.map(|a| self.matcher.fuzzy_match(a, filter).is_some())
233-
.unwrap_or(false)
234-
})
235-
.map(|f| {
236-
let label = f.alias.clone().unwrap_or_else(|| f.label.clone());
237-
Action {
238-
label,
239-
desc: f.path.clone(),
240-
action: f.path.clone(),
241-
args: None,
242-
}
243-
})
244-
.collect()
253+
self.list_entries(filter)
245254
}
246255

247256
fn name(&self) -> &str {
@@ -264,6 +273,12 @@ impl Plugin for FoldersPlugin {
264273
action: "query:f ".into(),
265274
args: None,
266275
},
276+
Action {
277+
label: "f list".into(),
278+
desc: "Folder".into(),
279+
action: "query:f list ".into(),
280+
args: None,
281+
},
267282
Action {
268283
label: "f add".into(),
269284
desc: "Folder".into(),

0 commit comments

Comments
 (0)