fix: 修复了wrap计算错误

This commit is contained in:
JuanZoran
2023-01-14 14:22:25 +08:00
parent fdd4f23181
commit 273fb8d2c1
9 changed files with 118 additions and 79 deletions

18
lua/Trans/util/init.lua Normal file
View File

@ -0,0 +1,18 @@
local function get_height(bufnr, winid)
if not vim.wo[winid].wrap then
return vim.api.nvim_buf_line_count(bufnr)
end
local width = vim.api.nvim_win_get_width(winid)
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
local height = 0
for i = 1, #lines do
height = height + math.max(1, (math.ceil(vim.fn.strwidth(lines[i]) / width)))
end
return height
end
return {
get_height = get_height,
}

View File

@ -1,10 +1,23 @@
-- 记录开始时间
local starttime = os.clock(); --> os.clock()用法
for i = 1, 10, 2 do
print(i)
local function pw(str)
-- local res = vim.fn.strdisplaywidth(str)
local res = vim.fn.strwidth(str)
print(res)
end
pw('n. either extremity of something that has length')
pw('n.the point in time at which something ends')
pw('n.the concluding parts of an event or occurrence')
pw('n.a final part or section')
-- 48
-- 43
-- 48
-- 25
-- 记录结束时间
local endtime = os.clock(); --> os.clock()用法