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