@@ -11,50 +11,108 @@ local db = require("papis.sqlite-wrapper")
11
11
12
12
local utils = require (" papis.utils" )
13
13
14
+ local get_multi = function (prompt_bufnr )
15
+ local picker = require (' telescope.actions.state' ).get_current_picker (prompt_bufnr )
16
+ local multi = picker :get_multi_selection ()
17
+ return multi
18
+ end
19
+
14
20
local M = {}
15
21
16
- --- This function inserts a formatted reference string at the cursor
22
+ --- This function inserts a formatted ref string at the cursor
17
23
--- @param prompt_bufnr number @The buffer number of the prompt
18
24
--- @param format_string string @The string to be inserted
19
25
M .ref_insert = function (prompt_bufnr , format_string )
20
- local entry = string.format (format_string , action_state .get_selected_entry ().id .ref )
26
+ local multi = get_multi (prompt_bufnr )
27
+
21
28
actions .close (prompt_bufnr )
22
- vim .api .nvim_put ({ entry }, " " , false , true )
29
+ local string_to_insert = " "
30
+ if vim .tbl_isempty (multi ) then
31
+ local ref = string.format (format_string , action_state .get_selected_entry ().id .ref )
32
+ string_to_insert = ref
33
+ else
34
+ for _ , entry in pairs (multi ) do
35
+ local ref = string.format (format_string , entry .id .ref )
36
+ string_to_insert = string_to_insert .. ref .. " "
37
+ end
38
+ end
39
+ vim .api .nvim_put ({ string_to_insert }, " " , false , true )
23
40
end
24
41
25
- --- This function inserts a formatted reference string at the cursor
42
+ --- This function inserts a formatted full reference at the cursor
26
43
--- @param prompt_bufnr number @The buffer number of the prompt
27
44
M .ref_insert_formatted = function (prompt_bufnr )
45
+ local multi = get_multi (prompt_bufnr )
46
+
28
47
actions .close (prompt_bufnr )
29
- local papis_id = action_state .get_selected_entry ().id .papis_id
30
- local entry = db .data :get ({ papis_id = papis_id })[1 ]
31
- local reference = config [" formatter" ].format_references_fn (entry )
48
+ local string_to_insert = " "
49
+ if vim .tbl_isempty (multi ) then
50
+ local papis_id = action_state .get_selected_entry ().id .papis_id
51
+ local full_entry = db .data :get ({ papis_id = papis_id })[1 ]
52
+ local full_reference = config [" formatter" ].format_references_fn (full_entry )
53
+ string_to_insert = full_reference
54
+ else
55
+ for _ , entry in pairs (multi ) do
56
+ local papis_id = entry .id .papis_id
57
+ local full_entry = db .data :get ({ papis_id = papis_id })[1 ]
58
+ local full_reference = config [" formatter" ].format_references_fn (full_entry )
59
+ string_to_insert = string_to_insert .. full_reference .. " "
60
+ end
61
+ end
32
62
33
- vim .api .nvim_put ({ reference }, " " , false , true )
63
+ vim .api .nvim_put ({ string_to_insert }, " " , false , true )
34
64
end
35
65
36
66
--- This function opens the files attached to the current entry
37
67
--- @param prompt_bufnr number @The buffer number of the prompt
38
68
M .open_file = function (prompt_bufnr )
39
- local papis_id = action_state .get_selected_entry ().id .papis_id
69
+ local multi = get_multi (prompt_bufnr )
70
+
40
71
actions .close (prompt_bufnr )
41
- utils :do_open_attached_files (papis_id )
72
+ if vim .tbl_isempty (multi ) then
73
+ local papis_id = action_state .get_selected_entry ().id .papis_id
74
+ utils :do_open_attached_files (papis_id )
75
+ else
76
+ for _ , entry in pairs (multi ) do
77
+ local papis_id = entry .id .papis_id
78
+ utils :do_open_attached_files (papis_id )
79
+ end
80
+ end
42
81
end
43
82
44
83
--- This function opens the note attached to the current entry
45
84
--- @param prompt_bufnr number @The buffer number of the prompt
46
85
M .open_note = function (prompt_bufnr )
47
- local papis_id = action_state .get_selected_entry ().id .papis_id
86
+ local multi = get_multi (prompt_bufnr )
87
+
48
88
actions .close (prompt_bufnr )
49
- utils :do_open_text_file (papis_id , " note" )
89
+ if vim .tbl_isempty (multi ) then
90
+ local papis_id = action_state .get_selected_entry ().id .papis_id
91
+ utils :do_open_text_file (papis_id , " note" )
92
+ else
93
+ for _ , entry in pairs (multi ) do
94
+ -- TODO: this only opens one note if a note needs to be created
95
+ local papis_id = entry .id .papis_id
96
+ utils :do_open_text_file (papis_id , " note" )
97
+ end
98
+ end
50
99
end
51
100
52
101
--- This function opens the info_file containing this entry's information
53
102
--- @param prompt_bufnr number @The buffer number of the prompt
54
103
M .open_info = function (prompt_bufnr )
55
- local papis_id = action_state .get_selected_entry ().id .papis_id
104
+ local multi = get_multi (prompt_bufnr )
105
+
56
106
actions .close (prompt_bufnr )
57
- utils :do_open_text_file (papis_id , " info" )
107
+ if vim .tbl_isempty (multi ) then
108
+ local papis_id = action_state .get_selected_entry ().id .papis_id
109
+ utils :do_open_text_file (papis_id , " info" )
110
+ else
111
+ for _ , entry in pairs (multi ) do
112
+ local papis_id = entry .id .papis_id
113
+ utils :do_open_text_file (papis_id , " info" )
114
+ end
115
+ end
58
116
end
59
117
60
118
return M
0 commit comments