diff --git a/lua/frecency/picker.lua b/lua/frecency/picker.lua index 79bf216..53a668e 100644 --- a/lua/frecency/picker.lua +++ b/lua/frecency/picker.lua @@ -1,6 +1,6 @@ local State = require "frecency.state" local Finder = require "frecency.finder" -local sorters = require "frecency.sorters" +local sorters = require "telescope.sorters" local log = require "plenary.log" local Path = require "plenary.path" --[[@as PlenaryPath]] local actions = require "telescope.actions" @@ -110,7 +110,7 @@ function Picker:start(opts) prompt_title = "Frecency", finder = finder, previewer = config_values.file_previewer(opts), - sorter = sorters.get_frecency_matcher(), + sorter = sorters.get_substr_matcher(), on_input_filter_cb = self:on_input_filter_cb(opts), attach_mappings = function(prompt_bufnr) return self:attach_mappings(prompt_bufnr) diff --git a/lua/frecency/sorters.lua b/lua/frecency/sorters.lua deleted file mode 100644 index 98b8b70..0000000 --- a/lua/frecency/sorters.lua +++ /dev/null @@ -1,63 +0,0 @@ -local sorters = require "telescope.sorters" -local util = require "telescope.utils" - -local M = {} - ----@param prompt string ----@return boolean -local function has_upper_case(prompt) - return not not prompt:match "%u" -end - ----@param prompt string ----@param display string ----@return { start: integer, finish: integer }[] -local function highlighter(_, prompt, display) - ---@type { start: integer, finish: integer }[] - local highlights = {} - display = has_upper_case(prompt) and display or display:lower() - - local search_terms = util.max_split(prompt, "%s") - local hl_start, hl_end - - for _, word in ipairs(search_terms) do - hl_start, hl_end = display:find(word, 1, true) - if hl_start then - table.insert(highlights, { start = hl_start, finish = hl_end }) - end - end - - return highlights -end - ----@param prompt string ----@param entry FrecencyEntry ----@return integer -local function scoring_function(_, prompt, _, entry) - if #prompt == 0 then - return 1 - end - - local display = has_upper_case(prompt) and entry.ordinal or entry.ordinal:lower() - - local search_terms = util.max_split(prompt, "%s") - for _, word in ipairs(search_terms) do - if not display:find(word, 1, true) then - return -1 - end - end - return entry.index -end - ----This is a sorter similar to telescope.sorters.get_substr_matcher. telescope's ----one always ignore cases, but this sorter deal with them like 'smartcase' way. -function M.get_frecency_matcher() - return vim.o.smartcase - and sorters.Sorter:new { - highlighter = highlighter, - scoring_function = scoring_function, - } - or sorters.get_substr_matcher() -end - -return M