Skip to content

Commit 287f5c3

Browse files
author
neo451
committed
feat: pick and also use qflist
1 parent 3ec5775 commit 287f5c3

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

lua/obsidian/commands/toc.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ return function()
1010
format_item = function(v)
1111
return v.display
1212
end,
13-
callback = function(v)
14-
vim.api.nvim_win_set_cursor(0, { v.lnum, 0 })
15-
end,
1613
})
1714
end,
1815
}

lua/obsidian/picker/_default.lua

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,30 @@ local ut = require "obsidian.picker.util"
1919
---
2020
M.pick = function(values, opts)
2121
opts = opts or {}
22-
vim.ui.select(values, {
23-
prompt = opts.prompt_title,
24-
format_item = opts.format_item or function(value)
25-
return ut.make_display(value)
26-
end,
27-
}, function(item)
28-
if opts.callback and item then
29-
if type(item) == "string" then
30-
item = { value = item }
22+
23+
if opts.callback then
24+
vim.ui.select(values, {
25+
prompt = opts.prompt_title,
26+
format_item = opts.format_item or function(value)
27+
return ut.make_display(value)
28+
end,
29+
}, function(item)
30+
if item then
31+
if type(item) == "string" then
32+
item = { value = item }
33+
end
34+
opts.callback(item)
3135
end
32-
opts.callback(item)
33-
end
34-
end)
36+
end)
37+
else
38+
-- HACK: all text
39+
values = vim.tbl_map(function(value)
40+
value.text = value.display
41+
return value
42+
end, values)
43+
vim.fn.setqflist(values)
44+
vim.cmd "copen"
45+
end
3546
end
3647

3748
--- Grep for a string.

0 commit comments

Comments
 (0)