2828--- @field add fun ( filename ?: string ): nil -- add file
2929--- @field cur_index fun (): number -- get index of current file
3030--- @field get_indexes fun (): marlin.file[] -- get indexes
31- --- @field move fun ( table : marlin.file[] , direction : marlin.movefun ): nil
32- --- @field move_down fun (): nil -- move index down
33- --- @field move_up fun (): nil -- move index up
31+ --- @field move fun ( table : marlin.file[] , direction : marlin.movefun , filename ?: string ): nil
32+ --- @field move_down fun ( filename ?: string ): nil -- move index down
33+ --- @field move_up fun ( filename ?: string ): nil -- move index up
3434--- @field num_indexes fun (): number -- get number of indexes
3535--- @field open fun ( index : number , opts : any ?): nil -- open index
3636--- @field open_all fun (): nil
@@ -182,17 +182,34 @@ marlin.get_indexes = function()
182182 return marlin .project_files [" files" ]
183183end
184184
185+ --- Return index of a filename
186+ ---
187+ --- @param filename string
188+ ---
189+ --- @return number | nil returns index of file or nil
190+ ---
191+ --- @usage `require("marlin").get_fileindex("/full/path/to/filename")`
192+ marlin .get_fileindex = function (filename )
193+ if filename then
194+ for idx , data in ipairs (marlin .project_files [" files" ]) do
195+ if data [" filename" ] == filename then
196+ return idx
197+ end
198+ end
199+ end
200+ return nil
201+ end
185202--- Generic move function for moving indexes
186203---
187204--- @param table string[] index table
188205--- @param direction marlin.movefun
189- marlin .move = function (table , direction )
206+ marlin .move = function (table , direction , filename )
190207 local indexes = marlin .num_indexes ()
191208 if indexes < 2 then
192209 return
193210 end
194211
195- local cur_index = marlin .cur_index ()
212+ local cur_index = marlin .get_fileindex ( filename ) or marlin . cur_index ()
196213 direction (table , cur_index , indexes )
197214end
198215
@@ -217,15 +234,15 @@ end
217234--- Move current index down
218235---
219236--- @usage `require('marlin').move_down()`
220- marlin .move_down = function ()
221- marlin .move (marlin .project_files [" files" ], down )
237+ marlin .move_down = function (filename )
238+ marlin .move (marlin .project_files [" files" ], down , filename )
222239end
223240
224241--- Move current index up
225242---
226243--- @usage `require('marlin').move_up()`
227- marlin .move_up = function ()
228- marlin .move (marlin .project_files [" files" ], up )
244+ marlin .move_up = function (filename )
245+ marlin .move (marlin .project_files [" files" ], up , filename )
229246end
230247
231248--- Return number of indexes for current project
0 commit comments