mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
feat(picker.matcher): moved length tiebreak to sorter instead
This commit is contained in:
parent
6ae87d9f62
commit
d5ccb301c1
2 changed files with 10 additions and 4 deletions
|
@ -101,6 +101,10 @@ local defaults = {
|
|||
return vim.o.columns >= 120 and "default" or "vertical"
|
||||
end,
|
||||
},
|
||||
sort = {
|
||||
-- default sort is by score, text length and index
|
||||
fields = { "score:desc", "#text", "idx" },
|
||||
},
|
||||
ui_select = true, -- replace `vim.ui.select` with the snacks picker
|
||||
---@class snacks.picker.formatters.Config
|
||||
formatters = {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
---@field prev_class number
|
||||
---@field in_gap boolean
|
||||
---@field str string
|
||||
---@field opts snacks.picker.matcher.Config
|
||||
local M = {}
|
||||
M.__index = M
|
||||
|
||||
|
@ -14,7 +15,6 @@ M.__index = M
|
|||
local SCORE_MATCH = 16
|
||||
local SCORE_GAP_START = -3
|
||||
local SCORE_GAP_EXTENSION = -1
|
||||
local SCORE_LEN = -0.01
|
||||
|
||||
local BONUS_BOUNDARY = SCORE_MATCH / 2 -- 8
|
||||
local BONUS_NONWORD = SCORE_MATCH / 2 -- 8
|
||||
|
@ -95,8 +95,10 @@ for prev = 0, 6 do
|
|||
end
|
||||
end
|
||||
|
||||
function M.new()
|
||||
---@param opts? snacks.picker.matcher.Config
|
||||
function M.new(opts)
|
||||
local self = setmetatable({}, M)
|
||||
self.opts = opts or {}
|
||||
self.score = 0
|
||||
self.consecutive = 0
|
||||
self.prev_class = CHAR_WHITE
|
||||
|
@ -121,14 +123,14 @@ end
|
|||
---@param first number
|
||||
function M:init(str, first)
|
||||
self.str = str
|
||||
self.score = #str * SCORE_LEN -- tiebreak by length
|
||||
self.score = 0
|
||||
self.consecutive = 0
|
||||
self.prev_class = CHAR_WHITE
|
||||
self.prev = nil
|
||||
if first > 1 then
|
||||
self.prev_class = CHAR_CLASS[str:byte(first - 1)] or CHAR_NONWORD
|
||||
end
|
||||
if not str:find(PATH_SEP, first + 1, true) then
|
||||
if self.opts.filename_bonus and not str:find(PATH_SEP, first + 1, true) then
|
||||
self.score = self.score + BONUS_NO_PATH_SEP
|
||||
end
|
||||
self.in_gap = false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue