diff --git a/lua/Trans/core/buffer.lua b/lua/Trans/core/buffer.lua index df25da3..1cc6adc 100644 --- a/lua/Trans/core/buffer.lua +++ b/lua/Trans/core/buffer.lua @@ -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 diff --git a/lua/Trans/core/conf.lua b/lua/Trans/core/conf.lua index df31deb..c691895 100644 --- a/lua/Trans/core/conf.lua +++ b/lua/Trans/core/conf.lua @@ -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 = '[', @@ -59,13 +59,13 @@ return { -- play = '_', -- Deprecated }, ---@type string[] auto close events - auto_close_events = { + auto_close_events = { 'InsertEnter', 'CursorMoved', 'BufLeave', }, ---@type table order to display translate result - order = { + order = { default = { 'str', 'translation', @@ -87,7 +87,7 @@ return { } }, ---@type table - icon = { + icon = { -- or use emoji list = '●', -- ● | ○ | ◉ | ◯ | ◇ | ◆ | ▪ | ▫ | ⬤ | 🟢 | 🟡 | 🟣 | 🟤 | 🟠| 🟦 | 🟨 | 🟧 | 🟥 | 🟪 | 🟫 | 🟩 | 🟦 star = '', -- ⭐ | ✴ | ✳ | ✲ | ✱ | ✰ | ★ | ☆ | 🌟 | 🌠 | 🌙 | 🌛 | 🌜 | 🌟 | 🌠 | 🌌 | 🌙 | diff --git a/lua/Trans/core/util.lua b/lua/Trans/core/util.lua index 9e4b527..bcd99f9 100644 --- a/lua/Trans/core/util.lua +++ b/lua/Trans/core/util.lua @@ -219,7 +219,6 @@ function M.list_fields(list, field) return ret end - ---@class Trans ---@field util TransUtil return M diff --git a/lua/Trans/frontend/hover/init.lua b/lua/Trans/frontend/hover/init.lua index 4e3c266..a26abaf 100644 --- a/lua/Trans/frontend/hover/init.lua +++ b/lua/Trans/frontend/hover/init.lua @@ -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 diff --git a/lua/Trans/util/node.lua b/lua/Trans/util/node.lua index f6abac0..a3573a4 100644 --- a/lua/Trans/util/node.lua +++ b/lua/Trans/util/node.lua @@ -83,7 +83,6 @@ local function format(args) return text(args) end - ---@class TransUtil ---@field node TransNodes