From b3168ff3f04bcfa96a3ef723319a6ad3e51a7600 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 24 Oct 2025 14:03:00 -0400 Subject: [PATCH] feat: center the curso --- lua/cp/runner/run_render.lua | 12 ++++++++++-- lua/cp/ui/views.lua | 13 ++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lua/cp/runner/run_render.lua b/lua/cp/runner/run_render.lua index 0847793..714ecd3 100644 --- a/lua/cp/runner/run_render.lua +++ b/lua/cp/runner/run_render.lua @@ -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? diff --git a/lua/cp/ui/views.lua b/lua/cp/ui/views.lua index 130da3b..23e2fc6 100644 --- a/lua/cp/ui/views.lua +++ b/lua/cp/ui/views.lua @@ -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)