feat: add split_width for better sentence display
This commit is contained in:
parent
a3b0a21d08
commit
9b8c091a33
lua/Trans
@ -74,21 +74,6 @@ function buffer:lines(i, j)
|
||||
return api.nvim_buf_get_lines(self.bufnr, i, j, false)
|
||||
end
|
||||
|
||||
-- ---Add Extmark to buffer
|
||||
-- ---@param linenr number line number should be set[one index]
|
||||
-- ---@param col_start number column start
|
||||
-- ---@param col_end number column end
|
||||
-- ---@param hl_group string highlight group
|
||||
-- ---@param ns number? highlight namespace
|
||||
-- function buffer:add_extmark(linenr, col_start, col_end, hl_group, ns)
|
||||
-- linenr = linenr and linenr - 1 or -1
|
||||
-- api.nvim_buf_set_extmark(self.bufnr, ns or -1, linenr, col_start, {
|
||||
-- end_line = linenr,
|
||||
-- end_col = col_end,
|
||||
-- hl_group = hl_group,
|
||||
-- })
|
||||
-- end
|
||||
|
||||
---Add highlight to buffer
|
||||
---@param linenr number line number should be set[one index]
|
||||
---@param hl_group string highlight group
|
||||
@ -182,6 +167,40 @@ function buffer.new()
|
||||
return new_buf
|
||||
end
|
||||
|
||||
--- HACK :available options:
|
||||
--- - id
|
||||
--- - end_row
|
||||
--- - end_col
|
||||
--- - hl_eol
|
||||
--- - virt_text
|
||||
--- - virt_text_pos
|
||||
--- - virt_text_win_col
|
||||
--- - hl_mode
|
||||
--- - virt_lines
|
||||
--- - virt_lines_above
|
||||
--- - virt_lines_leftcol
|
||||
--- - ephemeral
|
||||
--- - right_gravity
|
||||
--- - end_right_gravity
|
||||
--- - priority
|
||||
--- - strict
|
||||
--- - sign_text
|
||||
--- - sign_hl_group
|
||||
--- - number_hl_group
|
||||
--- - line_hl_group
|
||||
--- - cursorline_hl_group
|
||||
--- - conceal
|
||||
--- - ui_watched
|
||||
|
||||
---Add Extmark to buffer
|
||||
---@param ns number highlight namespace
|
||||
---@param linenr number line number should be set[one index]
|
||||
---@param col_start number column start
|
||||
function buffer:set_extmark(ns, linenr, col_start, opts)
|
||||
linenr = linenr and linenr - 1 or -1
|
||||
return api.nvim_buf_set_extmark(self.bufnr, ns, linenr, col_start, opts)
|
||||
end
|
||||
|
||||
---@class Trans
|
||||
---@field buffer TransBuffer
|
||||
return buffer
|
||||
|
@ -40,17 +40,17 @@ return {
|
||||
---@class TransHoverOpts : TransFrontendOpts
|
||||
hover = {
|
||||
---@type integer Max Width of Hover Window
|
||||
width = 37,
|
||||
width = 37,
|
||||
---@type integer Max Height of Hover Window
|
||||
height = 27,
|
||||
height = 27,
|
||||
---@type string -- see: /lua/Trans/style/spinner
|
||||
spinner = 'dots',
|
||||
spinner = 'dots',
|
||||
---@type string
|
||||
fallback_message = '{{notfound}} 翻译超时或没有找到相关的翻译',
|
||||
auto_resize = true,
|
||||
unlimit_sentence_width = true,
|
||||
padding = 10, -- padding for hover window width
|
||||
keymaps = {
|
||||
fallback_message = '{{notfound}} 翻译超时或没有找到相关的翻译',
|
||||
auto_resize = true,
|
||||
split_width = 60,
|
||||
padding = 10, -- padding for hover window width
|
||||
keymaps = {
|
||||
pageup = '[[',
|
||||
pagedown = ']]',
|
||||
pin = '<leader>[',
|
||||
@ -59,13 +59,13 @@ return {
|
||||
-- play = '_', -- Deprecated
|
||||
},
|
||||
---@type string[] auto close events
|
||||
auto_close_events = {
|
||||
auto_close_events = {
|
||||
'InsertEnter',
|
||||
'CursorMoved',
|
||||
'BufLeave',
|
||||
},
|
||||
---@type table<string, string[]> order to display translate result
|
||||
order = {
|
||||
order = {
|
||||
default = {
|
||||
'str',
|
||||
'translation',
|
||||
@ -87,7 +87,7 @@ return {
|
||||
}
|
||||
},
|
||||
---@type table<string, string>
|
||||
icon = {
|
||||
icon = {
|
||||
-- or use emoji
|
||||
list = '●', -- ● | ○ | ◉ | ◯ | ◇ | ◆ | ▪ | ▫ | ⬤ | 🟢 | 🟡 | 🟣 | 🟤 | 🟠| 🟦 | 🟨 | 🟧 | 🟥 | 🟪 | 🟫 | 🟩 | 🟦
|
||||
star = '', -- ⭐ | ✴ | ✳ | ✲ | ✱ | ✰ | ★ | ☆ | 🌟 | 🌠 | 🌙 | 🌛 | 🌜 | 🌟 | 🌠 | 🌌 | 🌙 |
|
||||
|
@ -219,7 +219,6 @@ function M.list_fields(list, field)
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
---@class Trans
|
||||
---@field util TransUtil
|
||||
return M
|
||||
|
@ -209,7 +209,11 @@ function M:process(data)
|
||||
local window = self.window
|
||||
if window and window:is_valid() then
|
||||
if opts.auto_resize then
|
||||
display_size.width = math.min(opts.width, display_size.width + opts.padding)
|
||||
display_size.width = math.max(
|
||||
math.min(opts.width, display_size.width + opts.padding),
|
||||
math.min(data.str:width(), opts.split_width)
|
||||
)
|
||||
|
||||
else
|
||||
display_size.width = nil
|
||||
end
|
||||
|
@ -83,7 +83,6 @@ local function format(args)
|
||||
return text(args)
|
||||
end
|
||||
|
||||
|
||||
---@class TransUtil
|
||||
---@field node TransNodes
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user