Compare commits

...

1 Commits

Author SHA1 Message Date
Dmitriy Kovalenko 1635a1ffde refactor: cleanup lua code 2026-05-20 10:00:11 -07:00
4 changed files with 7 additions and 57 deletions
+1 -2
View File
@@ -18,9 +18,8 @@ local M = {}
--- Render a file item line
--- @param item FileItem File item from Rust
--- @param ctx ListRenderContext Render context with all state
--- @param _item_idx number Item index (1-based)
--- @return string[] Array of line strings (always exactly 1)
function M.render_line(item, ctx, _item_idx)
function M.render_line(item, ctx)
local icons = require('fff.file_picker.icons')
local lines = {}
+1 -4
View File
@@ -14,10 +14,7 @@ local tresitter_highlight = require('fff.treesitter_hl')
---@param ctx table Render context
---@return string The header line string
local function build_group_header(item, ctx)
ctx.has_combo = false
---@diagnostic disable-next-line: param-type-mismatch
local lines = file_renderer.render_line(item, ctx, 0)
ctx.has_combo = false -- never has a combo in grep
local lines = file_renderer.render_line(item, ctx)
return lines[1]
end
+2 -48
View File
@@ -11,9 +11,6 @@ local M = {}
--- @field debug_enabled boolean Whether debug mode shows scores
--- @field prompt_position string 'top' or 'bottom'
--- @field has_combo boolean Whether combo boost is active
--- @field combo_header_line string|nil Formatted combo header line
--- @field combo_header_text_len number|nil Length of combo header text
--- @field combo_item_index number|nil Index of item with combo (usually 1)
--- @field display_start number Start index for displayed items (1)
--- @field display_end number End index for displayed items (#items)
--- @field iter_start number Iteration start
@@ -101,7 +98,7 @@ local function generate_item_lines(ctx)
local item = ctx.items[i]
local item_start_line = #lines + 1
local item_lines = renderer.render_line(item, ctx, i)
local item_lines = renderer.render_line(item, ctx)
vim.list_extend(lines, item_lines)
local item_end_line = #lines
@@ -227,7 +224,6 @@ end
--- @param list_win number List window handle
--- @param ns_id number Highlight namespace
--- @return number|nil separator_line 1-based buffer line of the separator (post-padding), nil if none
--- @return table<number, ItemLineMapping> item_to_lines
function M.render(ctx, list_buf, list_win, ns_id)
local lines, item_to_lines, separator_line = generate_item_lines(ctx)
@@ -255,49 +251,7 @@ function M.render(ctx, list_buf, list_win, ns_id)
end
end
return separator_line, item_to_lines
end
--- Get the buffer line for an item's content (selectable) line.
--- Used by picker_ui for cursor positioning after navigation.
--- @param item_to_lines table<number, ItemLineMapping>
--- @param item_index number 1-based item index
--- @return number|nil line 1-based buffer line, or nil if item not mapped
function M.get_content_line(item_to_lines, item_index)
local mapping = item_to_lines[item_index]
if not mapping then return nil end
return mapping.last
end
--- Get the buffer line for an item's first line (may be a virtual header).
--- Used by combo_renderer for overlay positioning.
--- @param item_to_lines table<number, ItemLineMapping>
--- @param item_index number 1-based item index
--- @return number|nil line 1-based buffer line, or nil if item not mapped
function M.get_first_line(item_to_lines, item_index)
local mapping = item_to_lines[item_index]
if not mapping then return nil end
return mapping.first
end
--- Check if an item has virtual (header) rows.
--- @param item_to_lines table<number, ItemLineMapping>
--- @param item_index number 1-based item index
--- @return boolean
function M.has_virtual_rows(item_to_lines, item_index)
local mapping = item_to_lines[item_index]
if not mapping then return false end
return mapping.virtual_count > 0
end
--- Count total buffer lines an item occupies (content + virtual).
--- @param item_to_lines table<number, ItemLineMapping>
--- @param item_index number 1-based item index
--- @return number
function M.get_line_count(item_to_lines, item_index)
local mapping = item_to_lines[item_index]
if not mapping then return 0 end
return mapping.last - mapping.first + 1
return separator_line
end
return M
+3 -3
View File
@@ -1939,7 +1939,7 @@ local function build_render_context()
}
end
local function finalize_render(separator_line, _item_to_lines, ctx)
local function finalize_render(separator_line, ctx)
if ctx.separator and separator_line then
-- Arrow points toward the prompt: matches sit between the separator and
-- the prompt, so the arrow visually leads the eye from "rest of list"
@@ -1979,12 +1979,12 @@ function M.render_list()
return
end
local separator_line, item_to_lines = list_renderer.render(ctx, M.state.list_buf, M.state.list_win, M.state.ns_id)
local separator_line = list_renderer.render(ctx, M.state.list_buf, M.state.list_win, M.state.ns_id)
-- For bottom prompt, always ensure content is anchored at the bottom after rendering
-- This prevents results from appearing in the middle when there are few items
if ctx.prompt_position == 'bottom' then scroll_to_bottom() end
finalize_render(separator_line, item_to_lines, ctx)
finalize_render(separator_line, ctx)
end
--- Build and set the preview window title for a given item and location.