Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Dynamic input width #162

Open
chrisgrieser opened this issue Jun 12, 2024 · 1 comment
Open

FR: Dynamic input width #162

chrisgrieser opened this issue Jun 12, 2024 · 1 comment
Labels
P2 Not a priority. PRs welcome

Comments

@chrisgrieser
Copy link
Contributor

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,
})
@stevearc
Copy link
Owner

Looks nice! I'd be open to looking at a PR

@stevearc stevearc added the P2 Not a priority. PRs welcome label Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Not a priority. PRs welcome
Projects
None yet
Development

No branches or pull requests

2 participants