diff --git a/lua/LspUI/_meta.lua b/lua/LspUI/_meta.lua index 53cbedf..8aed282 100644 --- a/lua/LspUI/_meta.lua +++ b/lua/LspUI/_meta.lua @@ -35,7 +35,7 @@ --- @field filter { whitelist: string[]?, blacklist:string[]? }? the filter of blacklist and whitelist, should be filetype list -- this is just for some keybind like definition, type definition, declaration, reference, implementation ---- @alias LspUI_pos_keybind_config { secondary: { jump: string?, jump_tab: string?, jump_split: string?, jump_vsplit: string?, toggle_fold:string?, quit:string?, hide_main:string?, fold_all:string?, expand_all:string?, enter: string? }?, main: { back: string?, hide_secondary: string? }? , transparency: number? } +--- @alias LspUI_pos_keybind_config { secondary: { jump: string?, jump_tab: string?, jump_split: string?, jump_vsplit: string?, toggle_fold: string?, next_file_entry: string?, prev_file_entry: string?, quit:string?, hide_main:string?, fold_all:string?, expand_all:string?, enter: string? }?, main: { back: string?, hide_secondary: string? }? , transparency: number? } -- TODO: change this -- TODO: replace above LspUI_pos_keybind_config with LspUI_pos_config diff --git a/lua/LspUI/config.lua b/lua/LspUI/config.lua index a75157e..d72bd36 100644 --- a/lua/LspUI/config.lua +++ b/lua/LspUI/config.lua @@ -108,6 +108,8 @@ local default_pos_keybind_config = { jump_vsplit = "sv", jump_tab = "t", toggle_fold = "", + next_file_entry = "J", + prev_file_entry = "K", quit = "q", hide_main = "h", fold_all = "w", diff --git a/lua/LspUI/pos_abstract.lua b/lua/LspUI/pos_abstract.lua index caf9efd..67d3636 100644 --- a/lua/LspUI/pos_abstract.lua +++ b/lua/LspUI/pos_abstract.lua @@ -336,6 +336,34 @@ local secondary_view_keybind = function() } ) + api.nvim_buf_set_keymap( + M.secondary_view_buffer(), + "n", + config.options.pos_keybind.secondary.next_file_entry, + "", + { + nowait = true, + noremap = true, + callback = function() + M.action.next_file_entry() + end, + } + ) + + api.nvim_buf_set_keymap( + M.secondary_view_buffer(), + "n", + config.options.pos_keybind.secondary.prev_file_entry, + "", + { + nowait = true, + noremap = true, + callback = function() + M.action.prev_file_entry() + end, + } + ) + api.nvim_buf_set_keymap( M.secondary_view_buffer(), "n", @@ -1017,6 +1045,64 @@ local action_toggle_fold = function() M.secondary_view_render() end +-- next file entry +local action_next_file_entry = function() + -- when current_item not exist, just return + if not current_item.uri then + return + end + local current_uri = current_item.uri + local line = 1 + local has_seen_current = false + for uri, val in pairs(M.datas()) do + if has_seen_current then + api.nvim_win_set_cursor(M.secondary_view_window(), { line, 0 }) + break + end + line = line + 1 + if not val.fold then + line = line + #val.range + end + + if uri == current_uri then + has_seen_current = true + end + end +end + +-- prev file entry +local action_prev_file_entry = function() + -- when current_item not exist, just return + if not current_item.uri then + return + end + local current_uri = current_item.uri + local line = 1 + local prev_range_nums = 0 + for uri, val in pairs(M.datas()) do + if uri == current_uri then + line = line - prev_range_nums + if line > 1 then + line = line - 1 + end + api.nvim_win_set_cursor(M.secondary_view_window(), { line, 0 }) + break + end + + line = line + 1 + if not val.fold then + prev_range_nums = #val.range + line = line + prev_range_nums + else + prev_range_nums = 0 + end + end + + print(string.format("prev file is %d", line)) + + -- api.nvim_win_set_cursor(M.secondary_view_window(), { line, 0 }) +end + local action_enter_main = function() if not M.main_view_hide() then api.nvim_set_current_win(M.main_view_window()) @@ -1124,6 +1210,12 @@ M.action = { toggle_fold = function() action_toggle_fold() end, + next_file_entry = function() + action_next_file_entry() + end, + prev_file_entry = function() + action_prev_file_entry() + end, enter_main = function() action_enter_main() end,