comparison src/testdir/test_edit.vim @ 25790:16a7d1154be8 v8.2.3430

patch 8.2.3430: no generic way to trigger an autocommand on mode change Commit: https://github.com/vim/vim/commit/f1e8876fa2359b572d262772747405d3616db670 Author: =?UTF-8?q?Magnus=20Gro=C3=9F?= <magnus.gross@rwth-aachen.de> Date: Sun Sep 12 13:39:55 2021 +0200 patch 8.2.3430: no generic way to trigger an autocommand on mode change Problem: No generic way to trigger an autocommand on mode change. Solution: Add the ModeChanged autocommand event. (Magnus Gross, closes https://github.com/vim/vim/issues/8856)
author Bram Moolenaar <Bram@vim.org>
date Sun, 12 Sep 2021 13:45:05 +0200
parents ec62e0764ffa
children 1a5351f6803f
comparison
equal deleted inserted replaced
25789:3afd5ab3d69a 25790:16a7d1154be8
1905 call assert_equal(['r', 'r'], getline(1, 2)) 1905 call assert_equal(['r', 'r'], getline(1, 2))
1906 bwipe! 1906 bwipe!
1907 set encoding=utf-8 1907 set encoding=utf-8
1908 endfunc 1908 endfunc
1909 1909
1910 " Test for ModeChanged pattern
1911 func Test_mode_changes()
1912 let g:count = 0
1913 func! DoIt()
1914 let g:count += 1
1915 endfunc
1916 let g:index = 0
1917 let g:mode_seq = ['n', 'i', 'n', 'v', 'V', 'n', 'V', 'v', 'n']
1918 func! TestMode()
1919 call assert_equal(g:mode_seq[g:index], get(v:event, "old_mode"))
1920 call assert_equal(g:mode_seq[g:index + 1], get(v:event, "new_mode"))
1921 call assert_equal(mode(), get(v:event, "new_mode"))
1922 let g:index += 1
1923 endfunc
1924
1925 au ModeChanged * :call TestMode()
1926 au ModeChanged n:* :call DoIt()
1927 call feedkeys("i\<esc>vV\<esc>", 'tnix')
1928 call assert_equal(2, g:count)
1929
1930 au ModeChanged V:v :call DoIt()
1931 call feedkeys("Vv\<esc>", 'tnix')
1932 call assert_equal(4, g:count)
1933
1934 call assert_equal(len(g:mode_seq) - 1, g:index)
1935
1936 au! ModeChanged
1937 delfunc TestMode
1938 unlet! g:mode_seq
1939 unlet! g:index
1940 delfunc DoIt
1941 unlet! g:count
1942 endfunc
1943
1910 " vim: shiftwidth=2 sts=2 expandtab 1944 " vim: shiftwidth=2 sts=2 expandtab