Skip to content

Commit

Permalink
fix: fix tab keycode support
Browse files Browse the repository at this point in the history
Also fixes not passing a mode to :KeySeer

And it fixes the builtin keymaps code.
  • Loading branch information
jokajak committed Aug 7, 2023
1 parent 682ac91 commit d9e59f9
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
9 changes: 7 additions & 2 deletions lua/keyseer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

local KeySeer = {}
local H = {}
local if_nil = vim.F.if_nil

--- Plugin setup
---
Expand All @@ -24,11 +25,14 @@ KeySeer.setup = function(config)
local args = vim.split(vim.trim(cmd.args), "%s+")
local mode
local valid_modes = { "n", "i", "v", "o", "x", "s", "l", "c", "t", "ic" }
if #args == 1 then
if #args == 1 and args[1] ~= nil and args[1] ~= "" then
if vim.tbl_contains(valid_modes, args[1]) then
mode = args[1]
else
error("Invalid mode specified. See map")
local Utils = require("keyseer.utils")
local D = require("keyseer.util.debug")
D.tprint(args)
Utils.error("Invalid mode specified. See map")
return
end
end
Expand All @@ -37,6 +41,7 @@ KeySeer.setup = function(config)
return
end
local bufnr = vim.api.nvim_get_current_buf()
mode = if_nil(mode, config.initial_mode)

local UI = require("keyseer.ui")
UI.show("home", mode, bufnr)
Expand Down
8 changes: 5 additions & 3 deletions lua/keyseer/keymaps/builtin_keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
local function keymapLike(t)
local mt = {
__newindex = function(tbl, key, value)
rawset(tbl, key, {
local keymap = {
lhs = key,
rhs = key,
desc = value,
})
}
rawset(tbl, #tbl + 1, keymap)
end,
}
setmetatable(t, mt)
Expand Down Expand Up @@ -57,7 +58,7 @@ M.n["D"] = "Delete to end of line"
M.n["e"] = "forward to the end of word [count] |inclusive|."
M.n["E"] = "Forward to the end of WORD [count] |inclusive|."
M.n["f"] = "Move to next char"
M.n["<C-L>"] = "* <Cmd>nohlsearch|diffupdate|normal! <C-L><CR>"
M.n["<C-L>"] = "See :help <C-L>"
M.n["h"] = "Left"
M.n["j"] = "Down"
M.n["k"] = "Up"
Expand Down Expand Up @@ -96,6 +97,7 @@ M.n["Up"] = "Up"
M.n["Down"] = "Down"
M.n["Left"] = "Left"
M.n["Right"] = "Right"
M.n["<Tab>"] = "See :help <Tab>"

M.v["#"] = '* y?\\V<C-R>"<CR>'
M.v["*"] = '* y?\\V<C-R>"<CR>'
Expand Down
1 change: 0 additions & 1 deletion lua/keyseer/keymaps/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ end
---@returns table
function Keymaps:process_keymaps(bufnr, mode)
mode = mode or Config.initial_mode
D.log("Keymaps", "Getting keymaps for %s", mode)
if Config.include_builtin_keymaps then
local preset_keymaps = BuiltInKeyMaps[mode]
self:add_keymaps(preset_keymaps)
Expand Down
1 change: 1 addition & 0 deletions lua/keyseer/keymaps/keypress.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function Keypress.get_keycode(keystring)
"<F9>",
"<F10>",
"<CR>",
"<Tab>",
}

if #key_presses > 1 then
Expand Down
1 change: 1 addition & 0 deletions lua/keyseer/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function Utils.parse_keystring(keystr, split_keypresses)
["Esc"] = "<Esc>",
["BS"] = "<BS>",
["CR"] = "<CR>",
["Tab"] = "<Tab>",
["lt"] = "<lt>",
["F1"] = "<F1>",
["F2"] = "<F2>",
Expand Down
1 change: 1 addition & 0 deletions tests/test_keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ T["keypress"]["finds keycodes"] = function()
eq_global(child, "Keypress.get_keycode('<F1>')", "<F1>")
eq_global(child, "Keypress.get_keycode('<F2>')", "<F2>")
eq_global(child, "Keypress.get_keycode('<CR>')", "<CR>")
eq_global(child, "Keypress.get_keycode('<Tab>')", "<Tab>")
end

return T
1 change: 1 addition & 0 deletions tests/test_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ T["utils"]["parses keystrings"] = function()
eq_global(child, "utils.parse_keystring('<CR>')", { { "<CR>" } })
eq_global(child, "utils.parse_keystring('<S-Up>')", { { "<Shift>", "Up" } })
eq_global(child, "utils.parse_keystring('<M-S>')", { { "<Meta>", "S" } })
eq_global(child, "utils.parse_keystring('<Tab>')", { { "<Tab>" } })
end

T["buttons"] = MiniTest.new_set()
Expand Down

0 comments on commit d9e59f9

Please sign in to comment.