Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cache for search #23

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading