Skip to content

Commit

Permalink
fix: cache for search
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed Dec 18, 2023
1 parent 6394c21 commit bb133c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lua/hawtkeys/score.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local config = require("hawtkeys")
local keyboardLayouts = require("hawtkeys.keyboards")
local tsSearch = require("hawtkeys.ts")
local utils = require("hawtkeys.utils")
local already_used_keys = {}

---@param key1 string
---@param key2 string
Expand Down Expand Up @@ -121,8 +122,9 @@ local function process_string(str)
table.insert(sortedScores, { combo = combo, score = score })
end
table.sort(sortedScores, utils.score_sort)

local already_used_keys = tsSearch.get_all_keymaps()
if already_used_keys == nil then
already_used_keys = tsSearch.get_all_keymaps()
end

local find_mapping = function(maps, lhs)
for _, value in ipairs(maps) do
Expand Down Expand Up @@ -205,6 +207,11 @@ local function scoreTable(str)
return resultTable
end

local function reset_already_used_keys()
already_used_keys = nil
end

return {
ScoreTable = scoreTable,
ResetAlreadyUsedKeys = reset_already_used_keys,
}
1 change: 1 addition & 0 deletions lua/hawtkeys/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ M.hide = function()
if SearchWin and vim.api.nvim_win_is_valid(SearchWin) then
vim.api.nvim_win_close(SearchWin, true)
end
Hawtkeys.ResetAlreadyUsedKeys()
SearchWin = nil
ResultWin = nil
vim.api.nvim_command("stopinsert")
Expand Down

0 comments on commit bb133c5

Please sign in to comment.