|
14 | 14 | ---@param is_note boolean |
15 | 15 | ---@return string[] |
16 | 16 | local function get_commands_by_context(commands, is_visual, is_note) |
17 | | - local choices = {} |
18 | | - for _, config in ipairs(vim.tbl_values(commands)) do |
19 | | - local include = true |
20 | | - if is_visual then |
21 | | - include = config.range ~= nil |
22 | | - else |
23 | | - include = config.range == nil |
24 | | - end |
25 | | - if include and not is_note then |
26 | | - include = not config.note_action |
27 | | - end |
28 | | - if include and not Obsidian.opts.templates.enabled then |
29 | | - include = config.name ~= "template" and config.name ~= "new_from_template" |
30 | | - end |
31 | | - if include and not Obsidian.opts.checkbox.enabled then |
32 | | - include = config.name ~= "toggle_checkbox" |
33 | | - end |
34 | | - if include and not Obsidian.opts.daily_notes.enabled then |
35 | | - include = config.name ~= "dailies" |
36 | | - and config.name ~= "today" |
37 | | - and config.name ~= "tomorrow" |
38 | | - and config.name ~= "yesterday" |
39 | | - end |
40 | | - if include and not Obsidian.opts.unique_note.enabled then |
41 | | - include = config.name ~= "unique_note" |
42 | | - end |
43 | | - if include and not Obsidian.opts.sync.enabled then |
44 | | - include = config.name ~= "sync" |
45 | | - end |
46 | | - if include then |
47 | | - choices[#choices + 1] = config.name |
48 | | - end |
49 | | - end |
50 | | - return choices |
| 17 | + local choices = vim.tbl_values(commands) |
| 18 | + ---@diagnostic disable-next-line: call-non-callable |
| 19 | + return vim |
| 20 | + .iter(choices) |
| 21 | + :filter(function(config) |
| 22 | + if is_visual then |
| 23 | + return config.range ~= nil |
| 24 | + else |
| 25 | + return config.range == nil |
| 26 | + end |
| 27 | + end) |
| 28 | + :filter(function(config) |
| 29 | + if is_note then |
| 30 | + return true |
| 31 | + else |
| 32 | + return not config.note_action |
| 33 | + end |
| 34 | + end) |
| 35 | + :filter(function(config) |
| 36 | + if not Obsidian.opts.templates.enabled then |
| 37 | + return config.name ~= "template" and config.name ~= "new_from_template" |
| 38 | + end |
| 39 | + return true |
| 40 | + end) |
| 41 | + :filter(function(config) |
| 42 | + if not Obsidian.opts.checkbox.enabled then |
| 43 | + return config.name ~= "toggle_checkbox" |
| 44 | + end |
| 45 | + return true |
| 46 | + end) |
| 47 | + :filter(function(config) |
| 48 | + if not Obsidian.opts.daily_notes.enabled then |
| 49 | + return config.name ~= "dailies" |
| 50 | + and config.name ~= "today" |
| 51 | + and config.name ~= "tomorrow" |
| 52 | + and config.name ~= "yesterday" |
| 53 | + end |
| 54 | + return true |
| 55 | + end) |
| 56 | + :filter(function(config) |
| 57 | + if not Obsidian.opts.unique_note.enabled then |
| 58 | + return config.name ~= "unique_note" |
| 59 | + end |
| 60 | + return true |
| 61 | + end) |
| 62 | + :filter(function(config) |
| 63 | + if not Obsidian.opts.sync.enabled then |
| 64 | + return config.name ~= "sync" |
| 65 | + end |
| 66 | + return true |
| 67 | + end) |
| 68 | + :map(function(config) |
| 69 | + return config.name |
| 70 | + end) |
| 71 | + :totable() |
51 | 72 | end |
52 | 73 | function M.show_menu(data) |
53 | 74 | local is_visual, is_note = data.range ~= 0, in_note() |
|
0 commit comments