andymass/vim-matchup

MatchParen(Cur) Highlight persists in virtual fold text

ribru17 opened this issue · 0 comments

Explain the issue

Basically, when using a plugin like nvim-ufo which captures the highlights of a line for the folding text, the MatchParen/MatchParenCur highlight persists in the fold text until the user moves the cursor over the specific corresponding bracket, then moves back off of it.

  1. What vim version are you using? NVIM v0.9.4
    Build type: Release
    LuaJIT 2.1.1700008891
    Using Tree-sitter vim-matchup
  2. Steps to reproduce: Fold some lines of code while the cursor is on an open bracket character
  3. Expected behavior: The MatchParen highlight will be cleared upon folding (as it would when moving the cursor)
  4. Observed behavior: The highlight remains in the fold text, and stays when the cursor moves anywhere, only disappearing if, say, the cursor was on the closing bracket in the first place, then folded, such that the cursor would eventually move off of the bracket properly. This bug only affects when folding while the cursor is over an open bracket, for some reason.

Minimal working example

Please provide a minimal working example, e.g.,

print {
  'hi',
}

print('hi')

Observe that when folding from the last character of line 1, the fold text keeps the MatchParen highlight when the cursor moves anywhere. If folding from line 3, the highlight is also applied initially but disappears properly upon moving the cursor anywhere.

Minimal vimrc file

Minimal setup (derived from the lazy.nvim package manager):

local root = vim.fn.fnamemodify('./.repro', ':p')

-- set stdpaths to use .repro
for _, name in ipairs { 'config', 'data', 'state', 'cache' } do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system {
    'git',
    'clone',
    '--filter=blob:none',
    '--single-branch',
    'https://github.com/folke/lazy.nvim.git',
    lazypath,
  }
end
vim.opt.runtimepath:prepend(lazypath)

vim.o.foldlevel = 99
vim.o.foldlevelstart = 99

-- install plugins
local plugins = {
  {
    'nvim-treesitter/nvim-treesitter',
    build = ':TSUpdate',
    event = { 'BufReadPost', 'BufNewFile' },
    config = function()
      require('nvim-treesitter.configs').setup {
        ensure_installed = {
          'lua',
        },
        highlight = {
          enable = true,
        },
      }
    end,
  },
  'ribru17/bamboo.nvim',
  'andymass/vim-matchup',
  {
    'kevinhwang91/nvim-ufo',
    dependencies = {
      'kevinhwang91/promise-async',
    },
    opts = {
      provider_selector = function(_, _, _)
        return { 'treesitter' }
      end,
    },
  },
  -- add this to your lua/plugins.lua, lua/plugins/init.lua,  or the file you keep your other plugins:
}
require('lazy').setup(plugins, {
  root = root .. '/plugins',
})

vim.cmd.colorscheme('bamboo')

Additional Context

This bug is not present when folding lines while the cursor is on a closing bracket, only when the cursor is on the first folded line.

Edit: an image example
matchupfoldbug