fix: fix typo and add debug print option

This commit is contained in:
JuanZoran
2023-03-17 22:17:17 +08:00
parent e56267ea8c
commit a6a5a33bff
6 changed files with 92 additions and 11 deletions

View File

@@ -106,7 +106,7 @@ end
function buffer:add_highlight(linenr, hl_group, col_start, col_end, ns)
-- vim.print(linenr, hl_group, col_start, col_end, ns)
main_loop(function()
linenr = linenr - 1 or -1
linenr = linenr - 1
col_start = col_start or 0
api.nvim_buf_add_highlight(self.bufnr, ns or -1, hl_group, linenr, col_start, col_end or -1)
end)
@@ -159,7 +159,7 @@ buffer.__index = function(self, key)
if res then
return res
elseif type(key) == 'number' then
-- return fn.getbufoneline(self.bufnr, key) -- Vimscript Function Or Lua API ?? -- INFO :v0.8.1 doesn't support getbufoneline
-- return fn.getbufoneline(self.bufnr, key) -- Vimscript Function Or Lua API ?? -- INFO :only work on neovim-nightly
return api.nvim_buf_get_lines(self.bufnr, key - 1, key, true)[1]
else
error('invalid key: ' .. key)

View File

@@ -16,6 +16,7 @@ return {
---@type string the directory for database file and password file
dir = os.getenv('HOME') .. '/.vim/dict',
query = 'fallback',
debug = true,
-- backend_order = {},
---@type 'default' | 'dracula' | 'tokyonight' global Trans theme [see lua/Trans/style/theme.lua]
theme = 'default', -- default | tokyonight | dracula
@@ -102,11 +103,11 @@ return {
no = '', -- ❌ | ❎ | ✖ | ✘ | ✗ |
cell = '', -- ■ | □ | ▇ | ▏ ▎ ▍ ▌ ▋ ▊ ▉ █
web = '󰖟', --🌍 | 🌎 | 🌏 | 🌐 |
tag = ' ',
tag = '',
pos = '',
translation = '󰊿',
definition = '󰗊',
exchange = '',
exchange = '',
},
},
},

View File

@@ -143,6 +143,43 @@ function M.main_loop(func)
coroutine.yield()
end
---Split text into paragraphs
---@param lines string[] text to be split
---@return string[][] paragraphs
function M.split_to_paragraphs(lines, opts)
--- TODO :More options and better algorithm to detect paragraphs
opts = opts or {}
local paragraphs = {}
local paragraph = {}
for _, line in ipairs(lines) do
if line == '' then
paragraphs[#paragraphs + 1] = paragraph
paragraph = {}
else
paragraph[#paragraph + 1] = line
end
end
return paragraphs
end
---Get visible lines in the window or current window
---@param opts { winid: integer, height: integer }?
---@return string[]
function M.visible_lines(opts)
opts = opts or {}
-- INFO : don't calculate the height of statusline and cmdheight or winbar?
local winid = opts.winid or 0
local win_height = opts.height or api.nvim_win_get_height(winid)
local current_line = api.nvim_win_get_cursor(winid)[1]
local current_relative_line = vim.fn.winline()
local _start = current_line - current_relative_line
local _end = _start + win_height - vim.o.cmdheight --[[ - 1 -- maybe 1 for statusline?? ]]
return api.nvim_buf_get_lines(0, _start, _end, false)
end
---@class Trans
---@field util TransUtil

View File

@@ -1,4 +1,5 @@
local api = vim.api
---@class Trans
local Trans = require("Trans")
---@class TransWindow
@@ -110,6 +111,7 @@ function window:resize(opts)
end
end
---Try to close window with animation?
function window:try_close()
local close_animation = self.animation.close