diff --git a/README.md b/README.md index 3e5decae..bc200b9c 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,12 @@ Using lazy.nvim: -- when yazi was successfully closed yazi_closed_successfully = function(chosen_file) end, }, + + -- the floating window scaling factor. 1 means 100%, 0.9 means 90%, etc. + floating_window_scaling_factor = 0.9, + + -- the winblend value for the floating window. See :h winblend + yazi_floating_window_winblend = 0, }, } ``` diff --git a/lua/yazi.lua b/lua/yazi.lua index c1391eb5..854eb9d4 100644 --- a/lua/yazi.lua +++ b/lua/yazi.lua @@ -21,7 +21,7 @@ function M.yazi(path) local prev_win = vim.api.nvim_get_current_win() - local win, buffer = window.open_floating_window() + local win, buffer = window.open_floating_window(M.config) os.remove(M.config.chosen_file_path) local cmd = string.format( diff --git a/lua/yazi/config.lua b/lua/yazi/config.lua index 065fd977..449d4bac 100644 --- a/lua/yazi/config.lua +++ b/lua/yazi/config.lua @@ -16,6 +16,9 @@ function M.default() ---@diagnostic disable-next-line: unused-local yazi_closed_successfully = function(_chosen_file) end, }, + + floating_window_scaling_factor = 0.9, + yazi_floating_window_winblend = 0, } end diff --git a/lua/yazi/types.lua b/lua/yazi/types.lua index 71adb48c..f44df9ce 100644 --- a/lua/yazi/types.lua +++ b/lua/yazi/types.lua @@ -4,6 +4,8 @@ ---@field public events_file_path? string "the path to a temporary file that will be created by yazi to store events" ---@field public open_file_function? fun(chosen_file: string): nil "a function that will be called when a file is chosen in yazi" ---@field public hooks? YaziConfigHooks +---@field public floating_window_scaling_factor? float "the scaling factor for the floating window. 1 means 100%, 0.9 means 90%, etc." +---@field public yazi_floating_window_winblend? float "the winblend value for the floating window. See :h winblend" ---@class YaziConfigHooks ---@field public yazi_opened? fun(preselected_path: string | nil): nil diff --git a/lua/yazi/window.lua b/lua/yazi/window.lua index 91642fe7..231c511f 100644 --- a/lua/yazi/window.lua +++ b/lua/yazi/window.lua @@ -1,17 +1,9 @@ local M = {} --- open floating window with nice borders +---@param config YaziConfig ---@return number | nil, number | nil -function M.open_floating_window() - local floating_window_scaling_factor = - vim.g.yazi_floating_window_scaling_factor - - -- Why is this required? - -- vim.g.yazi_floating_window_scaling_factor returns different types if the value is an integer or float - if type(floating_window_scaling_factor) == 'table' then - floating_window_scaling_factor = floating_window_scaling_factor[false] - end - +function M.open_floating_window(config) local status, plenary = pcall(require, 'plenary.window.float') if status @@ -19,14 +11,15 @@ function M.open_floating_window() and vim.g.yazi_floating_window_use_plenary ~= 0 then plenary.percentage_range_window( - floating_window_scaling_factor, - floating_window_scaling_factor + config.floating_window_scaling_factor, + config.floating_window_scaling_factor ) return end - local height = math.ceil(vim.o.lines * floating_window_scaling_factor) - 1 - local width = math.ceil(vim.o.columns * floating_window_scaling_factor) + local height = math.ceil(vim.o.lines * config.floating_window_scaling_factor) + - 1 + local width = math.ceil(vim.o.columns * config.floating_window_scaling_factor) local row = math.ceil(vim.o.lines - height) / 2 local col = math.ceil(vim.o.columns - width) / 2 @@ -86,7 +79,7 @@ function M.open_floating_window() vim.cmd('setlocal nocursorcolumn') vim.api.nvim_set_hl(0, 'YaziFloat', { link = 'Normal', default = true }) vim.cmd('setlocal winhl=NormalFloat:YaziFloat') - vim.cmd('set winblend=' .. vim.g.yazi_floating_window_winblend) + vim.cmd('set winblend=' .. config.yazi_floating_window_winblend) -- use autocommand to ensure that the border_buffer closes at the same time as the main buffer vim.cmd("autocmd WinLeave silent! execute 'hide'") diff --git a/plugin/yazi.vim b/plugin/yazi.vim deleted file mode 100644 index 75c97908..00000000 --- a/plugin/yazi.vim +++ /dev/null @@ -1,38 +0,0 @@ -scriptencoding utf-8 - -if exists('g:loaded_yazi_vim') | finish | endif - -let s:save_cpo = &cpoptions -set cpoptions&vim - -"""""""""""""""""""""""""""""""""""""""""""""""""""""" - -if !exists('g:yazi_floating_window_winblend') - let g:yazi_floating_window_winblend = 0 -endif - -if !exists('g:yazi_floating_window_scaling_factor') - let g:yazi_floating_window_scaling_factor = 0.9 -endif - -if exists('g:yazi_floating_window_corner_chars') - echohl WarningMsg - echomsg "`g:yazi_floating_window_corner_chars` is deprecated. Please use `g:yazi_floating_window_border_chars` instead." - echohl None - if !exists('g:yazi_floating_window_border_chars') - let g:yazi_floating_window_border_chars = g:yazi_floating_window_corner_chars - endif -endif - -if !exists('g:yazi_floating_window_border_chars') - let g:yazi_floating_window_border_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] -endif - -command! Yazi lua require'yazi'.yazi() - -"""""""""""""""""""""""""""""""""""""""""""""""""""""" - -let &cpoptions = s:save_cpo -unlet s:save_cpo - -let g:loaded_yazi_vim = 1