From 6657392a27a83c0eb030606f1e16211dc71a2be5 Mon Sep 17 00:00:00 2001 From: JuanZoran <1430359574@qq.com> Date: Thu, 26 Jan 2023 23:40:18 +0800 Subject: [PATCH] fix: add debug message --- lua/Trans/init.lua | 29 +++++++++++++---------------- lua/Trans/window.lua | 6 ++++-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lua/Trans/init.lua b/lua/Trans/init.lua index 661c684..5bd4672 100644 --- a/lua/Trans/init.lua +++ b/lua/Trans/init.lua @@ -1,11 +1,11 @@ local M = {} -local title = vim.fn.has('nvim-0.9') and{ - { '', 'TransTitleRound' }, - { ' Trans', 'TransTitle' }, - { '', 'TransTitleRound' }, - } or ' Trans' +local title = vim.fn.has('nvim-0.9') and { + { '', 'TransTitleRound' }, + { ' Trans', 'TransTitle' }, + { '', 'TransTitleRound' }, +} or ' Trans' M.conf = { view = { @@ -45,11 +45,7 @@ M.conf = { width = 0.8, height = 0.8, border = 'rounded', - title = { - { '', 'TransTitleRound' }, - { ' Trans', 'TransTitle' }, - { '', 'TransTitleRound' }, - }, + title = title, keymap = { quit = 'q', }, @@ -104,15 +100,16 @@ M.setup = function(opts) if opts then M.conf = vim.tbl_deep_extend('force', M.conf, opts) end - local hover = M.conf.hover + local float = M.conf.float - assert(hover.width > 1 and hover.height > 1) - assert(0 < float.width and float.width <= 1) - assert(0 < float.height and float.height <= 1) + if float.height < 0 and float.height <= 1 then + float.height = math.floor((vim.o.lines - vim.o.cmdheight - 1) * float.height) + end - float.height = math.floor((vim.o.lines - vim.o.cmdheight - 1) * float.height) - float.width = math.floor(vim.o.columns * float.width) + if float.width < 0 and float.width <= 1 then + float.width = math.floor(vim.o.columns * float.width) + end M.translate = require('Trans.translate') diff --git a/lua/Trans/window.lua b/lua/Trans/window.lua index 4630ad2..3df1ab3 100644 --- a/lua/Trans/window.lua +++ b/lua/Trans/window.lua @@ -213,8 +213,10 @@ return function(entry, option) end local bufnr = api.nvim_create_buf(false, true) - local winid = api.nvim_open_win(bufnr, entry, opt) - + local ok, winid = pcall(api.nvim_open_win, bufnr, entry, opt) + if not ok then + error('open window faild: ' .. vim.inspect(opt)) + end local win win = {