Skip to content

Commit 7854ad1

Browse files
committed
count len
1 parent ac2c459 commit 7854ad1

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lua/kide/tools/ai.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,19 @@ M.translate_float = function(request)
154154
local win = vim.api.nvim_open_win(buf, true, opts)
155155
vim.wo[win].number = false -- 不显示行号
156156

157-
local curlines = ""
157+
local curlines = 0
158158
local callback = function(data)
159159
-- 判断是否换行符
160160
if data == "\n" then
161-
curlines = ""
161+
curlines = 0
162162
else
163-
curlines = curlines .. data
163+
curlines = curlines + vim.fn.strdisplaywidth(data)
164164
end
165165

166166
-- 自动调整窗口宽度
167167
-- 出现在中文翻译为英文时, 英文长度会超过中文
168-
local l = vim.fn.strdisplaywidth(curlines)
169-
if l > width and l < max_width then
170-
width = l
168+
if curlines > width and curlines < max_width then
169+
width = curlines
171170
if vim.api.nvim_win_is_valid(win) then
172171
vim.api.nvim_win_set_width(win, width)
173172
end

0 commit comments

Comments
 (0)