ctrl_o_spec.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear = helpers.clear
  3. local eq = helpers.eq
  4. local eval = helpers.eval
  5. local expect = helpers.expect
  6. local feed = helpers.feed
  7. local insert = helpers.insert
  8. local meths = helpers.meths
  9. describe('insert-mode Ctrl-O', function()
  10. before_each(clear)
  11. it('enters command mode for one command', function()
  12. feed('ihello world<C-o>')
  13. feed(':let ctrlo = "test"<CR>')
  14. feed('iii')
  15. expect('hello worldiii')
  16. eq(1, eval('ctrlo ==# "test"'))
  17. end)
  18. it('re-enters insert mode at the end of the line when running startinsert', function()
  19. -- #6962
  20. feed('ihello world<C-o>')
  21. feed(':startinsert<CR>')
  22. feed('iii')
  23. expect('hello worldiii')
  24. end)
  25. it('re-enters insert mode at the beginning of the line when running startinsert', function()
  26. insert('hello world')
  27. feed('0<C-o>')
  28. feed(':startinsert<CR>')
  29. feed('aaa')
  30. expect('aaahello world')
  31. end)
  32. it('re-enters insert mode in the middle of the line when running startinsert', function()
  33. insert('hello world')
  34. feed('bi<C-o>')
  35. feed(':startinsert<CR>')
  36. feed('ooo')
  37. expect('hello oooworld')
  38. end)
  39. it("doesn't cancel Ctrl-O mode when processing event", function()
  40. feed('iHello World<c-o>')
  41. eq({mode='niI', blocking=false}, meths.get_mode()) -- fast event
  42. eq(2, eval('1+1')) -- causes K_EVENT key
  43. eq({mode='niI', blocking=false}, meths.get_mode()) -- still in ctrl-o mode
  44. feed('dd')
  45. eq({mode='i', blocking=false}, meths.get_mode()) -- left ctrl-o mode
  46. expect('') -- executed the command
  47. end)
  48. end)