feat: center the curso
This commit is contained in:
parent
6ff0320531
commit
b3168ff3f0
2 changed files with 22 additions and 3 deletions
|
|
@ -276,10 +276,13 @@ local function data_row(c, idx, tc, is_current, test_state)
|
|||
end
|
||||
|
||||
---@param test_state PanelState
|
||||
---@return string[], Highlight[] lines and highlight positions
|
||||
---@return string[] lines
|
||||
---@return Highlight[] highlights
|
||||
---@return integer current_test_line
|
||||
function M.render_test_list(test_state)
|
||||
local lines, highlights = {}, {}
|
||||
local c = compute_cols(test_state)
|
||||
local current_test_line = nil
|
||||
|
||||
table.insert(lines, top_border(c))
|
||||
table.insert(lines, header_line(c))
|
||||
|
|
@ -289,6 +292,11 @@ function M.render_test_list(test_state)
|
|||
local is_current = (i == test_state.current_index)
|
||||
local row, hi = data_row(c, i, tc, is_current, test_state)
|
||||
table.insert(lines, row)
|
||||
|
||||
if is_current then
|
||||
current_test_line = #lines
|
||||
end
|
||||
|
||||
if hi then
|
||||
hi.line = #lines - 1
|
||||
table.insert(highlights, hi)
|
||||
|
|
@ -327,7 +335,7 @@ function M.render_test_list(test_state)
|
|||
end
|
||||
end
|
||||
|
||||
return lines, highlights
|
||||
return lines, highlights, current_test_line or 1
|
||||
end
|
||||
|
||||
---@param ran_test_case RanTestCase?
|
||||
|
|
|
|||
|
|
@ -574,7 +574,7 @@ function M.toggle_panel(panel_opts)
|
|||
end
|
||||
run_render.setup_highlights()
|
||||
local test_state = run.get_panel_state()
|
||||
local tab_lines, tab_highlights = run_render.render_test_list(test_state)
|
||||
local tab_lines, tab_highlights, current_line = run_render.render_test_list(test_state)
|
||||
utils.update_buffer_content(
|
||||
test_buffers.tab_buf,
|
||||
tab_lines,
|
||||
|
|
@ -582,6 +582,17 @@ function M.toggle_panel(panel_opts)
|
|||
test_list_namespace
|
||||
)
|
||||
update_diff_panes()
|
||||
|
||||
if
|
||||
current_line
|
||||
and test_windows.tab_win
|
||||
and vim.api.nvim_win_is_valid(test_windows.tab_win)
|
||||
then
|
||||
vim.api.nvim_win_set_cursor(test_windows.tab_win, { current_line, 0 })
|
||||
vim.api.nvim_win_call(test_windows.tab_win, function()
|
||||
vim.cmd('normal! zz')
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
local function navigate_test_case(delta)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue