aboutsummaryrefslogtreecommitdiff
path: root/test/functional/autocmd/cursormoved_spec.lua
blob: 64b63c32059758bc381ea3aad619da7ed246f04f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
local helpers = require('test.functional.helpers')(after_each)

local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
local funcs = helpers.funcs
local source = helpers.source
local command = helpers.command

describe('CursorMoved', function()
  before_each(clear)

  it('is triggered after BufEnter when changing or splitting windows #11878 #12031', function()
    source([[
    call setline(1, 'foo')
    let g:log = []
    autocmd BufEnter * let g:log += ['BufEnter' .. expand("<abuf>")]
    autocmd CursorMoved * let g:log += ['CursorMoved' .. expand("<abuf>")]
    ]])
    eq({}, eval('g:log'))
    command('new')
    eq({'BufEnter2', 'CursorMoved2'}, eval('g:log'))
    command('wincmd w')
    eq({'BufEnter2', 'CursorMoved2', 'BufEnter1', 'CursorMoved1'}, eval('g:log'))
  end)

  it("is not triggered by functions that don't change the window", function()
    source([[
    let g:cursormoved = 0
    let g:buf = bufnr('%')
    vsplit foo
    autocmd CursorMoved * let g:cursormoved += 1
    call nvim_buf_set_lines(g:buf, 0, -1, v:true, ['aaa'])
    ]])
    eq({'aaa'}, funcs.nvim_buf_get_lines(eval('g:buf'), 0, -1, true))
    eq(0, eval('g:cursormoved'))
  end)

  it("is not triggered by cursor movement prior to first CursorMoved instantiation", function()
    source([[
    let g:cursormoved = 0
    autocmd! CursorMoved
    autocmd CursorMoved * let g:cursormoved += 1
    ]])
    eq(0, eval('g:cursormoved'))
  end)
end)