Skip to content

Commit

Permalink
refactor!: remove vimscript part of the plugin
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The plugin is now written in Lua and the vimscript part is removed.

All configuration must be done using Lua.

This change also allows configuring two values that were not possible to
configure before:
- floating_window_scaling_factor
- yazi_floating_window_winblend
  • Loading branch information
mikavilpas committed Apr 8, 2024
1 parent b5e1aa1 commit 4fbdf5a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 54 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
```
2 changes: 1 addition & 1 deletion lua/yazi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions lua/yazi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lua/yazi/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 8 additions & 15 deletions lua/yazi/window.lua
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
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
and vim.g.yazi_floating_window_use_plenary
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
Expand Down Expand Up @@ -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 <buffer> silent! execute 'hide'")
Expand Down
38 changes: 0 additions & 38 deletions plugin/yazi.vim

This file was deleted.

0 comments on commit 4fbdf5a

Please sign in to comment.