diff --git a/lua/Trans/core/handler.lua b/lua/Trans/core/handler.lua index 68d2182..e95e3d9 100644 --- a/lua/Trans/core/handler.lua +++ b/lua/Trans/core/handler.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: unused-local local M = {} local icon = require('Trans').conf.icon diff --git a/lua/Trans/core/init.lua b/lua/Trans/core/init.lua index 3346288..5f83335 100644 --- a/lua/Trans/core/init.lua +++ b/lua/Trans/core/init.lua @@ -8,6 +8,10 @@ local handler = require('Trans.core.handler') local function get_select() local s_start = vim.fn.getpos("v") local s_end = vim.fn.getpos(".") + if s_start[2] > s_end[2] or s_start[3] > s_end[3] then + s_start, s_end = s_end, s_start + end + local n_lines = math.abs(s_end[2] - s_start[2]) + 1 local lines = vim.api.nvim_buf_get_lines(0, s_start[2] - 1, s_end[2], false) lines[1] = string.sub(lines[1], s_start[3], -1) @@ -35,6 +39,7 @@ local function get_word(method) end end + M.translate = function(method, view) method = method or vim.api.nvim_get_mode().mode view = view or conf.view[method] diff --git a/lua/Trans/core/window.lua b/lua/Trans/core/window.lua index 7ecee19..52d26c6 100644 --- a/lua/Trans/core/window.lua +++ b/lua/Trans/core/window.lua @@ -102,6 +102,11 @@ M.load_float_opts = function() end end, { buffer = M.bufnr, silent = true }) + vim.keymap.set('n', '', function() + if api.nvim_win_is_valid(M.id) then + api.nvim_win_close(M.id, true) + end + end, { buffer = M.bufnr, silent = true }) end diff --git a/lua/Trans/init.lua b/lua/Trans/init.lua index ee0e2ab..ca3b821 100644 --- a/lua/Trans/init.lua +++ b/lua/Trans/init.lua @@ -34,7 +34,7 @@ M.conf = { -- }, }, icon = { - title = ' ', + title = ' ', --  star = '', -- notfound = '', -- yes = '',