This repository was archived by the owner on Feb 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
FR: Dynamic input width #162
Copy link
Copy link
Open
Labels
P2Not a priority. PRs welcomeNot a priority. PRs welcome
Description
So, I saw something similar in a folke plugin, and tinkered a bit with resizing the window depending on the content:
Pasted_image_2024-06-12_at_21.47.23.mp4
Here the quick-and-dirty solution I came up with. I feel like it would be a nice addition to Dressing itself. What do you think?
-- dynamically resize input field
vim.api.nvim_create_autocmd("FileType", {
group = vim.api.nvim_create_augroup("DressingInputWidth", {}),
pattern = "DressingInput",
callback = function(ctx)
local win = vim.api.nvim_get_current_win()
local startWidth = vim.api.nvim_win_get_width(win)
local winOpts = vim.api.nvim_win_get_config(win)
local pad = 3
vim.api.nvim_create_autocmd({ "TextChangedI", "TextChanged" }, {
buffer = ctx.buf,
callback = function()
local lineLength = #vim.api.nvim_get_current_line() + pad
local newWidth = math.max(startWidth, lineLength)
vim.api.nvim_win_set_config(win, {
relative = winOpts.relative,
row = winOpts.row,
col = math.floor((vim.o.columns - newWidth) / 2),
width = newWidth,
})
end,
})
end,
})Metadata
Metadata
Assignees
Labels
P2Not a priority. PRs welcomeNot a priority. PRs welcome