From bb133c545e6eb056425badb5fe0ab34056536e89 Mon Sep 17 00:00:00 2001 From: tris203 Date: Mon, 18 Dec 2023 22:24:20 +0000 Subject: [PATCH] fix: cache for search --- lua/hawtkeys/score.lua | 11 +++++++++-- lua/hawtkeys/ui.lua | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lua/hawtkeys/score.lua b/lua/hawtkeys/score.lua index 50ec9b9..8e87243 100644 --- a/lua/hawtkeys/score.lua +++ b/lua/hawtkeys/score.lua @@ -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 @@ -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 @@ -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, } diff --git a/lua/hawtkeys/ui.lua b/lua/hawtkeys/ui.lua index 8904453..e8f40d0 100644 --- a/lua/hawtkeys/ui.lua +++ b/lua/hawtkeys/ui.lua @@ -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")