From 0a2d05af700f218a6d5d557eef1894af9f42af81 Mon Sep 17 00:00:00 2001 From: JuanZoran <1430359574@qq.com> Date: Sat, 14 Jan 2023 21:30:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=8F=8D?= =?UTF-8?q?=E5=90=91=E9=80=89=E6=8B=A9=EF=BC=8C=E4=BD=8D=E7=BD=AE=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/Trans/core/handler.lua | 1 + lua/Trans/core/init.lua | 5 +++++ lua/Trans/core/window.lua | 5 +++++ lua/Trans/init.lua | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) 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 = '',