feat(matcher): call on_match after setting score

This commit is contained in:
Folke Lemaitre 2025-02-05 19:44:33 +01:00
parent c61114fb32
commit 23ce529fb6
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -313,8 +313,8 @@ function M:update(item)
if item.match_pos then if item.match_pos then
item.pos = nil item.pos = nil
end end
item.match_topk = nil
local score = self:match(item) local score = self:match(item)
item.match_tick, item.match_topk = self.tick, nil
if score ~= 0 then if score ~= 0 then
if item.score_add then if item.score_add then
score = score + item.score_add score = score + item.score_add
@ -332,16 +332,19 @@ function M:update(item)
score = score + (1 - 1 / (1 + item.frecency)) * BONUS_FRECENCY score = score + (1 - 1 / (1 + item.frecency)) * BONUS_FRECENCY
end end
if if
self.opts.cwd_bonus and (self.cwd == item.cwd or Snacks.picker.util.path(item):find(self.cwd, 1, true) == 1) self.opts.cwd_bonus
and (self.cwd == item.cwd or Snacks.picker.util.path(item):find(self.cwd, 1, true) == 1)
then then
score = score + BONUS_CWD score = score + BONUS_CWD
end end
end end
item.score = score
if self.opts.on_match then if self.opts.on_match then
self.opts.on_match(self, item) self.opts.on_match(self, item)
end end
else
item.score = 0
end end
item.match_tick, item.score, item.match_topk = self.tick, score, nil
return score > 0 return score > 0
end end