Skip to content

Commit 569d57a

Browse files
committed
feat: add ignorecase option
1 parent d7658ee commit 569d57a

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

lua/picker/config.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
local M = {}
22

33
local default = {
4+
filter = {
5+
ignorecase = false,
6+
},
47
window = {
58
width = 0.8,
69
height = 0.8,

lua/picker/filter.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ local fzy = require("picker.matchers.fzy")
44

55
---@param input string
66
---@param source PickerSource
7-
function M.filter(input, source)
7+
---@param ignorecase boolean
8+
function M.filter(input, source, ignorecase)
89
if #input == 0 then
910
local i = 1
1011
source.filter_items = vim.tbl_map(function(t)
@@ -15,19 +16,19 @@ function M.filter(input, source)
1516
if
1617
source.state.previous_input
1718
and #source.state.previous_input > 0
18-
and fzy.has_match(source.state.previous_input, input)
19+
and fzy.has_match(source.state.previous_input, input, ignorecase)
1920
then
2021
local rst = {}
2122
for _, v in ipairs(source.filter_items) do
22-
if fzy.has_match(input, v[4].str) then
23-
local p, s = fzy.positions(input, v[4].str)
23+
if fzy.has_match(input, v[4].str, ignorecase) then
24+
local p, s = fzy.positions(input, v[4].str, ignorecase)
2425
table.insert(rst, { _, p, s, v[4] })
2526
end
2627
end
2728
if source.state.filter_count < #source.state.items then
2829
for i = source.state.filter_count, #source.state.items do
29-
if fzy.has_match(input, source.state.items[i].str) then
30-
local p, s = fzy.positions(input, source.state.items[i].str)
30+
if fzy.has_match(input, source.state.items[i].str, ignorecase) then
31+
local p, s = fzy.positions(input, source.state.items[i].str, ignorecase)
3132
table.insert(rst, { _, p, s, source.state.items[i] })
3233
end
3334
end
@@ -36,8 +37,8 @@ function M.filter(input, source)
3637
else
3738
local rst = {}
3839
for i = 1, #source.state.items do
39-
if fzy.has_match(input, source.state.items[i].str) then
40-
local p, s = fzy.positions(input, source.state.items[i].str)
40+
if fzy.has_match(input, source.state.items[i].str, ignorecase) then
41+
local p, s = fzy.positions(input, source.state.items[i].str, ignorecase)
4142
table.insert(rst, { _, p, s, source.state.items[i] })
4243
end
4344
end

lua/picker/sources/picker_config.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@ local configs = {
1313
})
1414
end,
1515
},
16+
{
17+
name = "ignrecase",
18+
desc = "change filter ignrecase to true",
19+
func = function()
20+
require("picker").setup({
21+
filter = {
22+
ignorecase = true, --- bottom or top
23+
},
24+
})
25+
end,
26+
},
27+
{
28+
name = "noignrecase",
29+
desc = "change filter ignrecase to false",
30+
func = function()
31+
require("picker").setup({
32+
filter = {
33+
ignorecase = false, --- bottom or top
34+
},
35+
})
36+
end,
37+
},
1638
{
1739
name = "prompt-bottom",
1840
desc = "change the prompt position to bottom",

lua/picker/windows.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ function M.open(s, opt)
276276
insert_timer_id = vim.fn.timer_start(config.prompt.insert_timeout, function()
277277
local input = vim.api.nvim_buf_get_lines(promot_bufnr, 0, 1, false)[1]
278278
vim.api.nvim_win_set_cursor(list_winid, { 1, 1 })
279-
filter.filter(input, source)
279+
filter.filter(input, source, config.filter.ignorecase)
280280

281281
vim.api.nvim_buf_set_lines(
282282
list_bufnr,

0 commit comments

Comments
 (0)