stevearc / dressing.nvim

Neovim plugin to improve the default vim.ui interfaces
MIT License
1.69k stars 32 forks source link

`input` shows line numbers in normal mode. #157

Closed dk949 closed 1 month ago

dk949 commented 1 month ago

Describe the bug

With insert_only = false and win_options = { number = false } line numbers still appear in normal mode.

System information

       require("dressing").setup {
            select = {
                -- Set to false to disable the vim.ui.select implementation
                enabled = true,

                -- Priority list of preferred vim.select implementations
                backend = { "telescope", "nui", "builtin", "fzf" },

                -- Options for telescope selector
                -- These are passed into the telescope picker directly. Can be used like:
                -- telescope = require('telescope.themes').get_ivy({...})
                telescope = require('telescope.themes').get_dropdown({ initial_mode = "insert" }),
            },
            input = {
                insert_only = false,

                win_options = {
                    -- Disable line wrapping
                    wrap = false,
                    -- Indicator for when text exceeds window
                    list = true,
                    listchars = "precedes:…,extends:…",
                    -- Increase this for more context when text scrolls off the window
                    sidescrolloff = 0,
                    number = false,
                },

                mappings = {
                    n = {
                        ["<Esc>"] = "Close",
                        ["<CR>"] = "Confirm",
                    },
                    i = {
                        ["<CR>"] = "Confirm",
                        ["<Up>"] = "HistoryPrev",
                        ["<Down>"] = "HistoryNext",
                    },
                },
            },
        }

To Reproduce Steps to reproduce the behavior:

  1. Open input menu
  2. Go into normal mode

Screenshots 2024-05-21_1

dk949 commented 1 month ago

Turns out this was an issue with my config. I had the following options set in init.lua

vim.api.nvim_create_autocmd("InsertLeave", {
    pattern = "*",
    command = "setlocal relativenumber number",
    group = line_number_grp
})

vim.api.nvim_create_autocmd("InsertEnter", {
    pattern = "*",
    command = "setlocal norelativenumber",
    group = line_number_grp
})

Changing it to this solved the problem:

vim.api.nvim_create_autocmd("InsertLeave", {
    pattern = "*",
    callback = function()
        if vim.opt_local.number:get() then
            vim.opt_local.relativenumber = true
            vim.opt_local.number = true
        end
    end,
    group = line_number_grp
})

vim.api.nvim_create_autocmd("InsertEnter", {
    pattern = "*",
    callback = function()
        if vim.opt_local.number:get() then
            vim.opt_local.relativenumber = false
        end
    end,
    group = line_number_grp
})