chore: close window and buffer more safely
This commit is contained in:
@ -37,7 +37,7 @@ end
|
||||
|
||||
---Destory buffer
|
||||
function buffer:destroy()
|
||||
api.nvim_buf_delete(self.bufnr, { force = true })
|
||||
pcall(api.nvim_buf_delete, self.bufnr, { force = true })
|
||||
end
|
||||
|
||||
---Set buffer load keymap
|
||||
|
@ -37,7 +37,7 @@ function M.new(opts)
|
||||
data.backends[i] = Trans.backend[name]
|
||||
end
|
||||
|
||||
if Trans.util.is_English(str) then
|
||||
if Trans.util.is_english(str) then
|
||||
data.from = 'en'
|
||||
data.to = 'zh'
|
||||
else
|
||||
|
@ -59,8 +59,7 @@ local strategy = {
|
||||
|
||||
local name = backend.name
|
||||
---@cast backend TransBackend
|
||||
while result[name] == nil do
|
||||
if not update(backend) then break end
|
||||
while result[name] == nil and update(backend) do
|
||||
end
|
||||
|
||||
if result[name] then return true end
|
||||
@ -72,7 +71,6 @@ local strategy = {
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- HACK : Core process logic
|
||||
local function process(opts)
|
||||
opts = init_opts(opts)
|
||||
|
@ -72,7 +72,7 @@ end
|
||||
---Detect whether the string is English
|
||||
---@param str string
|
||||
---@return boolean
|
||||
function M.is_English(str)
|
||||
function M.is_english(str)
|
||||
local char = { str:byte(1, -1) }
|
||||
for i = 1, #str do
|
||||
if char[i] > 128 then
|
||||
|
@ -124,7 +124,8 @@ function window:try_close()
|
||||
}
|
||||
end
|
||||
|
||||
api.nvim_win_close(self.winid, true)
|
||||
|
||||
pcall(api.nvim_win_close, self.winid, true)
|
||||
end
|
||||
|
||||
---Set window local highlight group
|
||||
|
@ -39,9 +39,9 @@ local function check_binary_dependencies()
|
||||
}
|
||||
|
||||
binary_dependencies[3] = ({
|
||||
win = 'node',
|
||||
mac = 'say',
|
||||
linux = 'festival',
|
||||
win = 'node',
|
||||
mac = 'say',
|
||||
linux = 'festival',
|
||||
termux = 'termux-api-speak',
|
||||
})[Trans.system]
|
||||
|
||||
|
Reference in New Issue
Block a user