fix: selector preview (#2362)
This commit is contained in:
@@ -221,6 +221,11 @@ function FileSelector:show_selector_ui()
|
||||
selected_item_ids = self.selected_filepaths,
|
||||
provider_opts = Config.file_selector.provider_opts,
|
||||
on_select = function(item_ids) self:handle_path_selection(item_ids) end,
|
||||
get_preview_content = function(item_id)
|
||||
local content = Utils.read_file_from_buf_or_disk(item_id)
|
||||
local filetype = Utils.get_filetype(item_id)
|
||||
return table.concat(content or {}, "\n"), filetype
|
||||
end,
|
||||
})
|
||||
selector:open()
|
||||
end
|
||||
@@ -233,6 +238,11 @@ function FileSelector:show_selector_ui()
|
||||
selected_item_ids = self.selected_filepaths,
|
||||
provider_opts = Config.selector.provider_opts,
|
||||
on_select = function(item_ids) self:handle_path_selection(item_ids) end,
|
||||
get_preview_content = function(item_id)
|
||||
local content = Utils.read_file_from_buf_or_disk(item_id)
|
||||
local filetype = Utils.get_filetype(item_id)
|
||||
return table.concat(content or {}, "\n"), filetype
|
||||
end,
|
||||
})
|
||||
selector:open()
|
||||
end
|
||||
|
||||
@@ -53,6 +53,7 @@ local function create_model_entries(provider_name, provider_cfg)
|
||||
and {
|
||||
{
|
||||
name = provider_cfg.display_name or (provider_name .. "/" .. provider_cfg.model),
|
||||
display_name = provider_cfg.display_name or (provider_name .. "/" .. provider_cfg.model),
|
||||
provider_name = provider_name,
|
||||
model = provider_cfg.model,
|
||||
},
|
||||
@@ -127,6 +128,11 @@ function M.open()
|
||||
provider = Config.selector.provider,
|
||||
provider_opts = Config.selector.provider_opts,
|
||||
on_select = on_select,
|
||||
get_preview_content = function(item_id)
|
||||
local model = vim.iter(models):find(function(item) return item.name == item_id end)
|
||||
if not model then return "", "markdown" end
|
||||
return model.name, "markdown"
|
||||
end,
|
||||
})
|
||||
|
||||
selector:open()
|
||||
|
||||
@@ -26,7 +26,9 @@ function M.show(selector)
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local completed = false
|
||||
|
||||
---@diagnostic disable-next-line: undefined-global
|
||||
Snacks.picker.pick(vim.tbl_deep_extend("force", {
|
||||
source = "select",
|
||||
|
||||
@@ -570,6 +570,11 @@ function M.trim_space(text)
|
||||
return text:gsub("%s*", "")
|
||||
end
|
||||
|
||||
function M.trim_slashes(text)
|
||||
if not text then return text end
|
||||
return text:gsub("//n", "/n"):gsub("//r", "/r"):gsub("//t", "/t"):gsub('/"', '"')
|
||||
end
|
||||
|
||||
---@param original_lines string[]
|
||||
---@param target_lines string[]
|
||||
---@param compare_fn fun(line_a: string, line_b: string): boolean
|
||||
@@ -620,6 +625,20 @@ function M.fuzzy_match(original_lines, target_lines)
|
||||
target_lines,
|
||||
function(line_a, line_b) return M.trim_space(line_a) == M.trim_space(line_b) end
|
||||
)
|
||||
if start_line ~= nil and end_line ~= nil then return start_line, end_line end
|
||||
---trim slashes match
|
||||
start_line, end_line = M.try_find_match(
|
||||
original_lines,
|
||||
target_lines,
|
||||
function(line_a, line_b) return line_a == M.trim_slashes(line_b) end
|
||||
)
|
||||
if start_line ~= nil and end_line ~= nil then return start_line, end_line end
|
||||
---trim slashes and trim_space match
|
||||
start_line, end_line = M.try_find_match(
|
||||
original_lines,
|
||||
target_lines,
|
||||
function(line_a, line_b) return M.trim_space(line_a) == M.trim_space(M.trim_slashes(line_b)) end
|
||||
)
|
||||
return start_line, end_line
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user