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

Visual surround: selection disappears when using number toggle plugin #315

Open
3 tasks done
simonmandlik opened this issue Apr 17, 2024 · 3 comments
Open
3 tasks done
Assignees
Labels
bug Something isn't working

Comments

@simonmandlik
Copy link

simonmandlik commented Apr 17, 2024

Checklist

  • Have you tried updating the plugin to the latest version?
  • Have you checked the Breaking Changes issue?
  • Have you read through :h nvim-surround to see if there might be any relevant information there?

Neovim Version

NVIM v0.10.0-dev-2274+g1d5f86f69-Homebrew

Plugin Version

Tagged (Stable)

Minimal Configuration

local root = vim.fn.fnamemodify("./.repro", ":p")
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

local plugins = {
    {
        "kylechui/nvim-surround",
        version = "*", -- Use for stability; omit to use `main` branch for the latest features
        config = function()
            require("nvim-surround").setup {}
        end
    },
}

require("lazy").setup(plugins, { root = root .. "/plugins", })

vim.o.number = true

-- from https://github.com/sitiom/nvim-numbertoggle/blob/main/plugin/numbertoggle.lua
local augroup = vim.api.nvim_create_augroup("numbertoggle", {})

vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "CmdlineLeave", "WinEnter" }, {
   pattern = "*",
   group = augroup,
   callback = function()
      if vim.o.nu and vim.api.nvim_get_mode().mode ~= "i" then
         vim.opt.relativenumber = true
      end
   end,
})

vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "InsertEnter", "CmdlineEnter", "WinLeave" }, {
   pattern = "*",
   group = augroup,
   callback = function()
      if vim.o.nu then
         vim.opt.relativenumber = false
         vim.cmd "redraw"
      end
   end,
})

Sample Buffer

test test
test test

Keystroke Sequence

ejS

Expected behavior

This is what happens after I comment out everything after line 23 in the setup:

image

Actual behavior

image

Additional context

The surrounding still works, this is only a visual issue in the "pending" phase.

The code is from https://github.com/sitiom/nvim-numbertoggle/blob/main/plugin/numbertoggle.lua, but I copied it for easier reproduction

@simonmandlik simonmandlik added the bug Something isn't working label Apr 17, 2024
@kylechui kylechui self-assigned this May 29, 2024
@kylechui
Copy link
Owner

Sorry for missing this for... several weeks. The sample config you sent worked well and I was able to reproduce it on my machine. Unfortunately, I have no clue where/why exactly this happened, and I vaguely remember dealing with something like this in a previous issue. I'll take another look; note to myself is to check the save/restore view calls.

@kylechui
Copy link
Owner

kylechui commented May 30, 2024

Relevant issues/PRs: #278 #299 #312

@kylechui
Copy link
Owner

I did some snooping around with the minimal configuration and I believe I have figured out the problem. The forced redraw in numbertoggle autocommand is nuking the highlights from the buffer; removing it resolves the issue. This also applies to the highlight when, you enter command mode after creating a visual selection, e.g. :foobarbaz in nvim -u NONE vs. nvim -u minimal_config.lua. I'm not entirely sure what the fix is here, as I imagine the forced redraw is to ensure that the toggled line numbers update properly whenever the mode changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants