refactor: remove auto setup frontend keymap

This commit is contained in:
JuanZoran
2023-03-24 11:09:04 +08:00
parent 82fa2a008a
commit a4dff90064
4 changed files with 49 additions and 51 deletions

View File

@@ -160,10 +160,11 @@ end
---@nodiscard
---TransBuffer constructor
---@param bufnr? integer buffer handle
---@return TransBuffer
function buffer.new()
function buffer.new(bufnr)
local new_buf = setmetatable({}, buffer)
new_buf:init()
new_buf:init(bufnr)
return new_buf
end

View File

@@ -3,30 +3,6 @@ local conf = Trans.conf
local frontend_opts = conf.frontend
---Setup frontend Keymaps
---@param frontend TransFrontend
local function set_frontend_keymap(frontend)
local set = vim.keymap.set
local keymap_opts = {
silent = true,
-- expr = true,
-- nowait = true,
}
for action, key in pairs(frontend.opts.keymaps) do
set('n', key, function()
local instance = frontend.get_active_instance()
if instance then
coroutine.wrap(instance.execute)(instance, action)
else
return key
end
end, keymap_opts)
end
end
---@class TransFrontend
---@field opts TransFrontendOpts
---@field get_active_instance fun():TransFrontend?
@@ -34,6 +10,7 @@ end
---@field wait fun(self: TransFrontend): fun() Update wait status
---@field execute fun(action: string) @Execute action for frontend instance
---@field fallback fun() @Fallback method when no result
---@field setup? fun() @Setup method for frontend [optional] **NOTE: This method will be called when frontend is first used**
---@class Trans
---@field frontend TransFrontend
@@ -47,8 +24,9 @@ return setmetatable({}, {
frontend.opts = opts
self[name] = frontend
set_frontend_keymap(frontend)
if frontend.setup then
frontend.setup()
end
return frontend
end,
})