Skip to content

Commit

Permalink
checkpoint: start adding keymap management structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jokajak committed Jul 4, 2023
1 parent 7b10d1b commit 58459b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lua/keyseer/keymaps/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end
---@param bufnr buffer? The buffer for which to get keymaps
---@param mode string? Optional mode for which to get keymaps
---@returns table
function Keymaps:get_keymaps(bufnr, mode)
function Keymaps:process_keymaps(bufnr, mode)
local mode = mode or config.initial_mode
local bufnr = bufnr or vim.api.nvim_get_current_buf()
local global_keymaps = vim.api.nvim_get_keymap(mode)
Expand Down
55 changes: 33 additions & 22 deletions lua/keyseer/ui/panes/home.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,50 @@ local Keymaps = require("keyseer.keymaps")
local Utils = require("keyseer.utils")
-- Render help
local M = {
state = {
count = 0,
},
count = 0,
modifiers = {},
saved_keymaps = {},
}

-- TODO: Populate main
function M.render(ui)
local keyboard_opts = Config.keyboard
local keyboard
local keyboard_options = vim.deepcopy(keyboard_opts)
keyboard_options.layout = nil
function M.ensure_state(ui)
if not ui.state.keyboard then
local keyboard_opts = Config.keyboard
local keyboard
local keyboard_options = vim.deepcopy(keyboard_opts)
keyboard_options.layout = nil

if type(keyboard_opts.layout) == "string" then
keyboard = require("keyseer.keyboard." .. keyboard_opts.layout):new(keyboard_options)
else
---@type Keyboard
local layout = keyboard_opts.layout
keyboard = layout:new(keyboard_options)
if type(keyboard_opts.layout) == "string" then
keyboard = require("keyseer.keyboard." .. keyboard_opts.layout):new(keyboard_options)
else
---@type Keyboard
local layout = keyboard_opts.layout
keyboard = layout:new(keyboard_options)
end

ui.state.keyboard = keyboard
end
if not ui.state.keymaps then
ui.state.keymaps = Keymaps:new()
ui.state.keymaps:process_keymaps()
end
end

local keymaps = Keymaps:new()
keymaps:get_keymaps()
keyboard:populate_lines(ui, keymaps:get_current_keycaps())
ui.state.keyboard = keyboard
-- TODO: Populate main
function M.render(ui)
M.ensure_state(ui)
local current_keycaps = ui.state.keymaps:get_current_keycaps(ui.state.modifiers)
ui.state.keyboard:populate_lines(ui, current_keycaps)
end

---Update keymaps when entering the pane
function M.on_enter(ui)
M.state.count = M.state.count + 1
Utils.notify("Entering home for the " .. M.state.count .. " time.")
M.ensure_state(ui)
Utils.notify("Entering home")
end

---Update keymaps when exiting the pane
function M.on_exit(ui)
Utils.notify("Exiting home for the " .. M.state.count .. " time.")
Utils.notify("Exiting home")
end

return M

0 comments on commit 58459b9

Please sign in to comment.