@@ -10,6 +10,7 @@ local record M
10
10
record DepsHistoryEntry
11
11
crate_name : string
12
12
version : Version
13
+ line_mapping : {integer:Dependency}
13
14
line : integer -- 0-indexed
14
15
end
15
16
end
@@ -28,12 +29,10 @@ local Version = types.Version
28
29
local util = require ("crates .util ")
29
30
30
31
local goto_dep = async .wrap (function (ctx : DepsContext , line : integer )
31
- local index = popup .item_index (line )
32
32
local hist_entry = ctx .history [ctx .hist_idx ]
33
- local deps = hist_entry .version .deps as {Dependency}
34
33
35
- if not deps or not deps [ index ] then return end
36
- local selected_dependency = deps [ index ]
34
+ local selected_dependency = hist_entry . line_mapping [ line ]
35
+ if not selected_dependency then return end
37
36
38
37
-- update current entry
39
38
hist_entry .line = line
@@ -154,9 +153,13 @@ function M.open_deps(ctx: DepsContext, crate_name: string, version: Version, opt
154
153
local title = string .format (state .cfg .popup .text .title , crate_name .." "..version .num )
155
154
local deps_width = 0
156
155
local deps_text_index : {{HighlightText}} = {}
157
- local normal_deps_text : {{HighlightText}} = {}
158
- local build_deps_text : {{HighlightText}} = {}
159
- local dev_deps_text : {{HighlightText}} = {}
156
+ local record HlTextDepList
157
+ {HighlightText}
158
+ dep : Dependency
159
+ end
160
+ local normal_deps_text : {HlTextDepList} = {}
161
+ local build_deps_text : {HlTextDepList} = {}
162
+ local dev_deps_text : {HlTextDepList} = {}
160
163
161
164
for _ ,d in ipairs (deps ) do
162
165
local t : HighlightText = {}
@@ -168,7 +171,7 @@ function M.open_deps(ctx: DepsContext, crate_name: string, version: Version, opt
168
171
t .hl = state .cfg .popup .highlight .dependency
169
172
end
170
173
171
- local line = { t }
174
+ local line = { t, dep = d }
172
175
if d .kind == "normal " then
173
176
table .insert (normal_deps_text , line )
174
177
elseif d .kind == "build " then
@@ -199,25 +202,49 @@ function M.open_deps(ctx: DepsContext, crate_name: string, version: Version, opt
199
202
end
200
203
201
204
local deps_text : {{HighlightText}} = {}
205
+ local line_mapping = {}
206
+ local line_idx = popup .TOP_OFFSET
202
207
if # normal_deps_text > 0 then
203
208
table .insert (deps_text , {{ text = state.cfg.popup.text.normal_dependencies_title, hl = state.cfg.popup.highlight.normal_dependencies_title }})
204
- vim .list_extend (deps_text , normal_deps_text )
209
+ line_idx = line_idx + 1
210
+
211
+ for _ ,t in ipairs (normal_deps_text ) do
212
+ table .insert (deps_text , t )
213
+ line_mapping [line_idx ] = t .dep
214
+ line_idx = line_idx + 1
215
+ end
205
216
end
206
217
if # build_deps_text > 0 then
207
218
if # deps_text > 0 then
208
219
table .insert (deps_text , {})
220
+ line_idx = line_idx + 1
209
221
end
210
222
table .insert (deps_text , {{ text = state.cfg.popup.text.build_dependencies_title, hl = state.cfg.popup.highlight.build_dependencies_title }})
211
- vim .list_extend (deps_text , build_deps_text )
223
+ line_idx = line_idx + 1
224
+
225
+ for _ ,t in ipairs (build_deps_text ) do
226
+ table .insert (deps_text , t )
227
+ line_mapping [line_idx ] = t .dep
228
+ line_idx = line_idx + 1
229
+ end
212
230
end
213
231
if # dev_deps_text > 0 then
214
232
if # deps_text > 0 then
215
233
table .insert (deps_text , {})
234
+ line_idx = line_idx + 1
216
235
end
217
236
table .insert (deps_text , {{ text = state.cfg.popup.text.dev_dependencies_title, hl = state.cfg.popup.highlight.dev_dependencies_title }})
218
- vim .list_extend (deps_text , dev_deps_text )
237
+ line_idx = line_idx + 1
238
+
239
+ for _ ,t in ipairs (dev_deps_text ) do
240
+ table .insert (deps_text , t )
241
+ line_mapping [line_idx ] = t .dep
242
+ line_idx = line_idx + 1
243
+ end
219
244
end
220
245
246
+ ctx .history [ctx .hist_idx ].line_mapping = line_mapping
247
+
221
248
local width = popup .win_width (title , deps_width + vers_width )
222
249
local height = popup .win_height (deps_text )
223
250
0 commit comments