vim-patch:9.1.0167: Changing buffer in another window causes it to show matchparen (#27820)

Problem:  Changing buffer in another window using win_execute() causes
          it to show matchparen (after 9.0.0969).
Solution: Delay highlighting with SafeState in BufWinEnter.
          (zeertzjq)

closes: vim/vim#14177

49ffb6b428
This commit is contained in:
zeertzjq
2024-03-12 07:19:47 +08:00
committed by GitHub
parent 6481da3015
commit e20e5ecf0a
3 changed files with 70 additions and 9 deletions

View File

@@ -22,7 +22,8 @@ let s:has_matchaddpos = exists('*matchaddpos')
augroup matchparen augroup matchparen
" Replace all matchparen autocommands " Replace all matchparen autocommands
autocmd! CursorMoved,CursorMovedI,WinEnter,BufWinEnter,WinScrolled * call s:Highlight_Matching_Pair() autocmd! CursorMoved,CursorMovedI,WinEnter,WinScrolled * call s:Highlight_Matching_Pair()
autocmd! BufWinEnter * autocmd SafeState * ++once call s:Highlight_Matching_Pair()
autocmd! WinLeave,BufLeave * call s:Remove_Matches() autocmd! WinLeave,BufLeave * call s:Remove_Matches()
if exists('##TextChanged') if exists('##TextChanged')
autocmd! TextChanged,TextChangedI * call s:Highlight_Matching_Pair() autocmd! TextChanged,TextChangedI * call s:Highlight_Matching_Pair()

View File

@@ -61,20 +61,55 @@ describe('matchparen', function()
set hidden set hidden
call setline(1, ['()']) call setline(1, ['()'])
normal 0 normal 0
func OtherBuffer()
enew
exe "normal iaa\<Esc>0"
endfunc
]]) ]])
screen:expect(screen1) screen:expect(screen1)
exec('call OtherBuffer()')
screen:expect(screen2)
feed('<C-^>')
screen:expect(screen1)
feed('<C-^>')
screen:expect(screen2)
end)
-- oldtest: Test_matchparen_win_execute()
it('matchparen highlight when switching buffer in win_execute()', function()
local screen = Screen.new(20, 5)
screen:set_default_attr_ids({
[1] = { background = Screen.colors.Cyan },
[2] = { reverse = true, bold = true },
[3] = { reverse = true },
})
screen:attach()
exec([[ exec([[
enew source $VIMRUNTIME/plugin/matchparen.vim
exe "normal iaa\<Esc>0" let s:win = win_getid()
call setline(1, '{}')
split
func SwitchBuf()
call win_execute(s:win, 'enew | buffer #')
endfunc
]])
screen:expect([[
{1:^{}} |
{2:[No Name] [+] }|
{} |
{3:[No Name] [+] }|
|
]]) ]])
screen:expect(screen2)
feed('<C-^>') -- Switching buffer away and back shouldn't change matchparen highlight.
screen:expect(screen1) exec('call SwitchBuf()')
screen:expect_unchanged()
feed('<C-^>')
screen:expect(screen2)
end) end)
-- oldtest: Test_matchparen_pum_clear() -- oldtest: Test_matchparen_pum_clear()

View File

@@ -61,6 +61,31 @@ func Test_matchparen_clear_highlight()
call StopVimInTerminal(buf) call StopVimInTerminal(buf)
endfunc endfunc
" Test for matchparen highlight when switching buffer in win_execute()
func Test_matchparen_win_execute()
CheckScreendump
let lines =<< trim END
source $VIMRUNTIME/plugin/matchparen.vim
let s:win = win_getid()
call setline(1, '{}')
split
func SwitchBuf()
call win_execute(s:win, 'enew | buffer #')
endfunc
END
call writefile(lines, 'XMatchparenWinExecute', 'D')
let buf = RunVimInTerminal('-S XMatchparenWinExecute', #{rows: 5})
call VerifyScreenDump(buf, 'Test_matchparen_win_execute_1', {})
" Switching buffer away and back shouldn't change matchparen highlight.
call term_sendkeys(buf, ":call SwitchBuf()\<CR>:\<Esc>")
call VerifyScreenDump(buf, 'Test_matchparen_win_execute_1', {})
call StopVimInTerminal(buf)
endfunc
" Test for scrolling that modifies buffer during visual block " Test for scrolling that modifies buffer during visual block
func Test_matchparen_pum_clear() func Test_matchparen_pum_clear()
CheckScreendump CheckScreendump