refactor: remove auto setup frontend keymap
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -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,
|
||||
})
|
||||
|
Reference in New Issue
Block a user