From cbf47ebdaa800fbcd0610f36fe682a02c2274385 Mon Sep 17 00:00:00 2001 From: JuanZoran <1430359574@qq.com> Date: Sat, 18 Feb 2023 13:13:32 +0800 Subject: [PATCH] fix: fix window is not valid --- lua/Trans/init.lua | 3 ++- lua/Trans/view/float.lua | 1 + lua/Trans/view/hover.lua | 4 +++- lua/Trans/window.lua | 4 +++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lua/Trans/init.lua b/lua/Trans/init.lua index 94796a8..85f018f 100644 --- a/lua/Trans/init.lua +++ b/lua/Trans/init.lua @@ -20,11 +20,12 @@ local win_title = fn.has('nvim-0.9') == 1 and { -- " ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝", --} + string.width = api.nvim_strwidth string.isEn = function(self) local char = { self:byte(1, -1) } for i = 1, #self do - if char[i] > 127 then + if char[i] > 128 then return false end end diff --git a/lua/Trans/view/float.lua b/lua/Trans/view/float.lua index 16fae4a..15c7d49 100644 --- a/lua/Trans/view/float.lua +++ b/lua/Trans/view/float.lua @@ -82,6 +82,7 @@ local function process() end return function(word) + buffer:init() -- TODO :online query -- local float = conf.float vim.notify([[ diff --git a/lua/Trans/view/hover.lua b/lua/Trans/view/hover.lua index 37ee5b8..7b09fca 100644 --- a/lua/Trans/view/hover.lua +++ b/lua/Trans/view/hover.lua @@ -1,9 +1,10 @@ local api = vim.api local conf = require('Trans').conf local hover = conf.hover -local buffer = require('Trans.buffer')() local error_msg = conf.icon.notfound .. ' 没有找到相关的翻译' +local buffer = require('Trans.buffer')() + local node = require('Trans.node') local it, t, f = node.item, node.text, node.format @@ -375,6 +376,7 @@ return function(word) width = width, height = math.min(buffer:height(width), hover.height) } + run(function() win:set('wrap', true) handle_keymap(win, word) diff --git a/lua/Trans/window.lua b/lua/Trans/window.lua index 621142e..72dccf0 100644 --- a/lua/Trans/window.lua +++ b/lua/Trans/window.lua @@ -27,7 +27,9 @@ end ---@param option string option name ---@param value any function window:set(option, value) - api.nvim_win_set_option(self.winid, option, value) + if self:is_valid() then + api.nvim_win_set_option(self.winid, option, value) + end end ---@param name string option name