cursor_spec.lua 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local thelpers = require('test.functional.terminal.helpers')
  4. local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim
  5. local testprg, command = helpers.testprg, helpers.command
  6. local nvim_prog = helpers.nvim_prog
  7. local eq, eval = helpers.eq, helpers.eval
  8. local matches = helpers.matches
  9. local feed_command = helpers.feed_command
  10. local hide_cursor = thelpers.hide_cursor
  11. local show_cursor = thelpers.show_cursor
  12. describe(':terminal cursor', function()
  13. local screen
  14. before_each(function()
  15. clear()
  16. screen = thelpers.screen_setup()
  17. end)
  18. it('moves the screen cursor when focused', function()
  19. thelpers.feed_data('testing cursor')
  20. screen:expect([[
  21. tty ready |
  22. testing cursor{1: } |
  23. |
  24. |
  25. |
  26. |
  27. {3:-- TERMINAL --} |
  28. ]])
  29. end)
  30. it('is highlighted when not focused', function()
  31. feed('<c-\\><c-n>')
  32. screen:expect([[
  33. tty ready |
  34. {2:^ } |
  35. |
  36. |
  37. |
  38. |
  39. |
  40. ]])
  41. end)
  42. describe('with number column', function()
  43. before_each(function()
  44. feed('<c-\\><c-n>:set number<cr>')
  45. end)
  46. it('is positioned correctly when unfocused', function()
  47. screen:expect([[
  48. {7: 1 }tty ready |
  49. {7: 2 }^rows: 6, cols: 46 |
  50. {7: 3 }{2: } |
  51. {7: 4 } |
  52. {7: 5 } |
  53. {7: 6 } |
  54. :set number |
  55. ]])
  56. end)
  57. it('is positioned correctly when focused', function()
  58. screen:expect([[
  59. {7: 1 }tty ready |
  60. {7: 2 }^rows: 6, cols: 46 |
  61. {7: 3 }{2: } |
  62. {7: 4 } |
  63. {7: 5 } |
  64. {7: 6 } |
  65. :set number |
  66. ]])
  67. feed('i')
  68. helpers.poke_eventloop()
  69. screen:expect([[
  70. {7: 1 }tty ready |
  71. {7: 2 }rows: 6, cols: 46 |
  72. {7: 3 }{1: } |
  73. {7: 4 } |
  74. {7: 5 } |
  75. {7: 6 } |
  76. {3:-- TERMINAL --} |
  77. ]])
  78. end)
  79. end)
  80. describe('when invisible', function()
  81. it('is not highlighted and is detached from screen cursor', function()
  82. if helpers.pending_win32(pending) then return end
  83. hide_cursor()
  84. screen:expect([[
  85. tty ready |
  86. |
  87. |
  88. |
  89. |
  90. |
  91. {3:-- TERMINAL --} |
  92. ]])
  93. show_cursor()
  94. screen:expect([[
  95. tty ready |
  96. {1: } |
  97. |
  98. |
  99. |
  100. |
  101. {3:-- TERMINAL --} |
  102. ]])
  103. -- same for when the terminal is unfocused
  104. feed('<c-\\><c-n>')
  105. hide_cursor()
  106. screen:expect([[
  107. tty ready |
  108. ^ |
  109. |
  110. |
  111. |
  112. |
  113. |
  114. ]])
  115. show_cursor()
  116. screen:expect([[
  117. tty ready |
  118. {2:^ } |
  119. |
  120. |
  121. |
  122. |
  123. |
  124. ]])
  125. end)
  126. end)
  127. end)
  128. describe('cursor with customized highlighting', function()
  129. local screen
  130. before_each(function()
  131. clear()
  132. nvim('command', 'highlight TermCursor ctermfg=45 ctermbg=46 cterm=NONE')
  133. nvim('command', 'highlight TermCursorNC ctermfg=55 ctermbg=56 cterm=NONE')
  134. screen = Screen.new(50, 7)
  135. screen:set_default_attr_ids({
  136. [1] = {foreground = 45, background = 46},
  137. [2] = {foreground = 55, background = 56},
  138. [3] = {bold = true},
  139. })
  140. screen:attach({rgb=false})
  141. command('call termopen(["'..testprg('tty-test')..'"])')
  142. feed_command('startinsert')
  143. end)
  144. it('overrides the default highlighting', function()
  145. screen:expect([[
  146. tty ready |
  147. {1: } |
  148. |
  149. |
  150. |
  151. |
  152. {3:-- TERMINAL --} |
  153. ]])
  154. feed('<c-\\><c-n>')
  155. screen:expect([[
  156. tty ready |
  157. {2:^ } |
  158. |
  159. |
  160. |
  161. |
  162. |
  163. ]])
  164. end)
  165. end)
  166. describe('buffer cursor position is correct in terminal without number column', function()
  167. local screen
  168. local function setup_ex_register(str)
  169. screen = thelpers.screen_setup(0, '["'..nvim_prog
  170. ..[[", "-u", "NONE", "-i", "NONE", "-E", "--cmd", "let @r = ']]..str..[['", ]]
  171. -- <Left> and <Right> don't always work
  172. ..[["--cmd", "cnoremap <C-X> <Left>", "--cmd", "cnoremap <C-O> <Right>"]]..']', 70)
  173. screen:expect([[
  174. |
  175. |
  176. |
  177. |
  178. Entering Ex mode. Type "visual" to go to Normal mode. |
  179. :{1: } |
  180. {3:-- TERMINAL --} |
  181. ]])
  182. end
  183. before_each(clear)
  184. describe('in a line with no multibyte characters or trailing spaces,', function()
  185. before_each(function()
  186. setup_ex_register('aaaaaaaa')
  187. end)
  188. it('at the end', function()
  189. feed('<C-R>r')
  190. screen:expect([[
  191. |
  192. |
  193. |
  194. |
  195. Entering Ex mode. Type "visual" to go to Normal mode. |
  196. :aaaaaaaa{1: } |
  197. {3:-- TERMINAL --} |
  198. ]])
  199. eq({6, 9}, eval('nvim_win_get_cursor(0)'))
  200. feed([[<C-\><C-N>]])
  201. screen:expect([[
  202. |
  203. |
  204. |
  205. |
  206. Entering Ex mode. Type "visual" to go to Normal mode. |
  207. :aaaaaaa^a{2: } |
  208. |
  209. ]])
  210. eq({6, 8}, eval('nvim_win_get_cursor(0)'))
  211. end)
  212. it('near the end', function()
  213. feed('<C-R>r<C-X><C-X>')
  214. screen:expect([[
  215. |
  216. |
  217. |
  218. |
  219. Entering Ex mode. Type "visual" to go to Normal mode. |
  220. :aaaaaa{1:a}a |
  221. {3:-- TERMINAL --} |
  222. ]])
  223. eq({6, 7}, eval('nvim_win_get_cursor(0)'))
  224. feed([[<C-\><C-N>]])
  225. screen:expect([[
  226. |
  227. |
  228. |
  229. |
  230. Entering Ex mode. Type "visual" to go to Normal mode. |
  231. :aaaaa^a{2:a}a |
  232. |
  233. ]])
  234. eq({6, 6}, eval('nvim_win_get_cursor(0)'))
  235. end)
  236. it('near the start', function()
  237. feed('<C-R>r<C-B><C-O>')
  238. screen:expect([[
  239. |
  240. |
  241. |
  242. |
  243. Entering Ex mode. Type "visual" to go to Normal mode. |
  244. :a{1:a}aaaaaa |
  245. {3:-- TERMINAL --} |
  246. ]])
  247. eq({6, 2}, eval('nvim_win_get_cursor(0)'))
  248. feed([[<C-\><C-N>]])
  249. screen:expect([[
  250. |
  251. |
  252. |
  253. |
  254. Entering Ex mode. Type "visual" to go to Normal mode. |
  255. :^a{2:a}aaaaaa |
  256. |
  257. ]])
  258. eq({6, 1}, eval('nvim_win_get_cursor(0)'))
  259. end)
  260. end)
  261. describe('in a line with single-cell multibyte characters and no trailing spaces,', function()
  262. before_each(function()
  263. setup_ex_register('µµµµµµµµ')
  264. end)
  265. it('at the end', function()
  266. feed('<C-R>r')
  267. screen:expect([[
  268. |
  269. |
  270. |
  271. |
  272. Entering Ex mode. Type "visual" to go to Normal mode. |
  273. :µµµµµµµµ{1: } |
  274. {3:-- TERMINAL --} |
  275. ]])
  276. eq({6, 17}, eval('nvim_win_get_cursor(0)'))
  277. feed([[<C-\><C-N>]])
  278. screen:expect([[
  279. |
  280. |
  281. |
  282. |
  283. Entering Ex mode. Type "visual" to go to Normal mode. |
  284. :µµµµµµµ^µ{2: } |
  285. |
  286. ]])
  287. eq({6, 15}, eval('nvim_win_get_cursor(0)'))
  288. end)
  289. it('near the end', function()
  290. feed('<C-R>r<C-X><C-X>')
  291. screen:expect([[
  292. |
  293. |
  294. |
  295. |
  296. Entering Ex mode. Type "visual" to go to Normal mode. |
  297. :µµµµµµ{1:µ}µ |
  298. {3:-- TERMINAL --} |
  299. ]])
  300. eq({6, 13}, eval('nvim_win_get_cursor(0)'))
  301. feed([[<C-\><C-N>]])
  302. screen:expect([[
  303. |
  304. |
  305. |
  306. |
  307. Entering Ex mode. Type "visual" to go to Normal mode. |
  308. :µµµµµ^µ{2:µ}µ |
  309. |
  310. ]])
  311. eq({6, 11}, eval('nvim_win_get_cursor(0)'))
  312. end)
  313. it('near the start', function()
  314. feed('<C-R>r<C-B><C-O>')
  315. screen:expect([[
  316. |
  317. |
  318. |
  319. |
  320. Entering Ex mode. Type "visual" to go to Normal mode. |
  321. :µ{1:µ}µµµµµµ |
  322. {3:-- TERMINAL --} |
  323. ]])
  324. eq({6, 3}, eval('nvim_win_get_cursor(0)'))
  325. feed([[<C-\><C-N>]])
  326. screen:expect([[
  327. |
  328. |
  329. |
  330. |
  331. Entering Ex mode. Type "visual" to go to Normal mode. |
  332. :^µ{2:µ}µµµµµµ |
  333. |
  334. ]])
  335. eq({6, 1}, eval('nvim_win_get_cursor(0)'))
  336. end)
  337. end)
  338. describe('in a line with single-cell composed multibyte characters and no trailing spaces,', function()
  339. if helpers.pending_win32(pending) then return end -- These tests fail on Windows. Encoding problem?
  340. before_each(function()
  341. setup_ex_register('µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳')
  342. end)
  343. it('at the end', function()
  344. feed('<C-R>r')
  345. screen:expect([[
  346. |
  347. |
  348. |
  349. |
  350. Entering Ex mode. Type "visual" to go to Normal mode. |
  351. :µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1: } |
  352. {3:-- TERMINAL --} |
  353. ]])
  354. eq({6, 33}, eval('nvim_win_get_cursor(0)'))
  355. feed([[<C-\><C-N>]])
  356. screen:expect([[
  357. |
  358. |
  359. |
  360. |
  361. Entering Ex mode. Type "visual" to go to Normal mode. |
  362. :µ̳µ̳µ̳µ̳µ̳µ̳µ̳^µ̳{2: } |
  363. |
  364. ]])
  365. eq({6, 29}, eval('nvim_win_get_cursor(0)'))
  366. end)
  367. it('near the end', function()
  368. feed('<C-R>r<C-X><C-X>')
  369. screen:expect([[
  370. |
  371. |
  372. |
  373. |
  374. Entering Ex mode. Type "visual" to go to Normal mode. |
  375. :µ̳µ̳µ̳µ̳µ̳µ̳{1:µ̳}µ̳ |
  376. {3:-- TERMINAL --} |
  377. ]])
  378. eq({6, 25}, eval('nvim_win_get_cursor(0)'))
  379. feed([[<C-\><C-N>]])
  380. screen:expect([[
  381. |
  382. |
  383. |
  384. |
  385. Entering Ex mode. Type "visual" to go to Normal mode. |
  386. :µ̳µ̳µ̳µ̳µ̳^µ̳{2:µ̳}µ̳ |
  387. |
  388. ]])
  389. eq({6, 21}, eval('nvim_win_get_cursor(0)'))
  390. end)
  391. it('near the start', function()
  392. feed('<C-R>r<C-B><C-O>')
  393. screen:expect([[
  394. |
  395. |
  396. |
  397. |
  398. Entering Ex mode. Type "visual" to go to Normal mode. |
  399. :µ̳{1:µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ |
  400. {3:-- TERMINAL --} |
  401. ]])
  402. eq({6, 5}, eval('nvim_win_get_cursor(0)'))
  403. feed([[<C-\><C-N>]])
  404. screen:expect([[
  405. |
  406. |
  407. |
  408. |
  409. Entering Ex mode. Type "visual" to go to Normal mode. |
  410. :^µ̳{2:µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ |
  411. |
  412. ]])
  413. eq({6, 1}, eval('nvim_win_get_cursor(0)'))
  414. end)
  415. end)
  416. describe('in a line with double-cell multibyte characters and no trailing spaces,', function()
  417. if helpers.pending_win32(pending) then return end -- These tests fail on Windows. Encoding problem?
  418. before_each(function()
  419. setup_ex_register('哦哦哦哦哦哦哦哦')
  420. end)
  421. it('at the end', function()
  422. feed('<C-R>r')
  423. screen:expect([[
  424. |
  425. |
  426. |
  427. |
  428. Entering Ex mode. Type "visual" to go to Normal mode. |
  429. :哦哦哦哦哦哦哦哦{1: } |
  430. {3:-- TERMINAL --} |
  431. ]])
  432. eq({6, 25}, eval('nvim_win_get_cursor(0)'))
  433. feed([[<C-\><C-N>]])
  434. screen:expect([[
  435. |
  436. |
  437. |
  438. |
  439. Entering Ex mode. Type "visual" to go to Normal mode. |
  440. :哦哦哦哦哦哦哦^哦{2: } |
  441. |
  442. ]])
  443. eq({6, 22}, eval('nvim_win_get_cursor(0)'))
  444. end)
  445. it('near the end', function()
  446. feed('<C-R>r<C-X><C-X>')
  447. screen:expect([[
  448. |
  449. |
  450. |
  451. |
  452. Entering Ex mode. Type "visual" to go to Normal mode. |
  453. :哦哦哦哦哦哦{1:哦}哦 |
  454. {3:-- TERMINAL --} |
  455. ]])
  456. eq({6, 19}, eval('nvim_win_get_cursor(0)'))
  457. feed([[<C-\><C-N>]])
  458. screen:expect([[
  459. |
  460. |
  461. |
  462. |
  463. Entering Ex mode. Type "visual" to go to Normal mode. |
  464. :哦哦哦哦哦^哦{2:哦}哦 |
  465. |
  466. ]])
  467. eq({6, 16}, eval('nvim_win_get_cursor(0)'))
  468. end)
  469. it('near the start', function()
  470. feed('<C-R>r<C-B><C-O>')
  471. screen:expect([[
  472. |
  473. |
  474. |
  475. |
  476. Entering Ex mode. Type "visual" to go to Normal mode. |
  477. :哦{1:哦}哦哦哦哦哦哦 |
  478. {3:-- TERMINAL --} |
  479. ]])
  480. eq({6, 4}, eval('nvim_win_get_cursor(0)'))
  481. feed([[<C-\><C-N>]])
  482. screen:expect([[
  483. |
  484. |
  485. |
  486. |
  487. Entering Ex mode. Type "visual" to go to Normal mode. |
  488. :^哦{2:哦}哦哦哦哦哦哦 |
  489. |
  490. ]])
  491. eq({6, 1}, eval('nvim_win_get_cursor(0)'))
  492. end)
  493. end)
  494. it('at the end of a line with trailing spaces #16234', function()
  495. setup_ex_register('aaaaaaaa ')
  496. feed('<C-R>r')
  497. screen:expect([[
  498. |
  499. |
  500. |
  501. |
  502. Entering Ex mode. Type "visual" to go to Normal mode. |
  503. :aaaaaaaa {1: } |
  504. {3:-- TERMINAL --} |
  505. ]])
  506. matches('^:aaaaaaaa [ ]*$', eval('nvim_get_current_line()'))
  507. eq({6, 13}, eval('nvim_win_get_cursor(0)'))
  508. feed([[<C-\><C-N>]])
  509. screen:expect([[
  510. |
  511. |
  512. |
  513. |
  514. Entering Ex mode. Type "visual" to go to Normal mode. |
  515. :aaaaaaaa ^ {2: } |
  516. |
  517. ]])
  518. eq({6, 12}, eval('nvim_win_get_cursor(0)'))
  519. end)
  520. end)
  521. describe('buffer cursor position is correct in terminal with number column', function()
  522. local screen
  523. local function setup_ex_register(str)
  524. screen = thelpers.screen_setup(0, '["'..nvim_prog
  525. ..[[", "-u", "NONE", "-i", "NONE", "-E", "--cmd", "let @r = ']]..str..[['", ]]
  526. -- <Left> and <Right> don't always work
  527. ..[["--cmd", "cnoremap <C-X> <Left>", "--cmd", "cnoremap <C-O> <Right>"]]..']', 70)
  528. screen:expect([[
  529. {7: 1 } |
  530. {7: 2 } |
  531. {7: 3 } |
  532. {7: 4 } |
  533. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  534. {7: 6 }:{1: } |
  535. {3:-- TERMINAL --} |
  536. ]])
  537. end
  538. before_each(function()
  539. clear()
  540. command('set number')
  541. end)
  542. describe('in a line with no multibyte characters or trailing spaces,', function()
  543. before_each(function()
  544. setup_ex_register('aaaaaaaa')
  545. end)
  546. it('at the end', function()
  547. feed('<C-R>r')
  548. screen:expect([[
  549. {7: 1 } |
  550. {7: 2 } |
  551. {7: 3 } |
  552. {7: 4 } |
  553. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  554. {7: 6 }:aaaaaaaa{1: } |
  555. {3:-- TERMINAL --} |
  556. ]])
  557. eq({6, 9}, eval('nvim_win_get_cursor(0)'))
  558. feed([[<C-\><C-N>]])
  559. screen:expect([[
  560. {7: 1 } |
  561. {7: 2 } |
  562. {7: 3 } |
  563. {7: 4 } |
  564. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  565. {7: 6 }:aaaaaaa^a{2: } |
  566. |
  567. ]])
  568. eq({6, 8}, eval('nvim_win_get_cursor(0)'))
  569. end)
  570. it('near the end', function()
  571. feed('<C-R>r<C-X><C-X>')
  572. screen:expect([[
  573. {7: 1 } |
  574. {7: 2 } |
  575. {7: 3 } |
  576. {7: 4 } |
  577. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  578. {7: 6 }:aaaaaa{1:a}a |
  579. {3:-- TERMINAL --} |
  580. ]])
  581. eq({6, 7}, eval('nvim_win_get_cursor(0)'))
  582. feed([[<C-\><C-N>]])
  583. screen:expect([[
  584. {7: 1 } |
  585. {7: 2 } |
  586. {7: 3 } |
  587. {7: 4 } |
  588. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  589. {7: 6 }:aaaaa^a{2:a}a |
  590. |
  591. ]])
  592. eq({6, 6}, eval('nvim_win_get_cursor(0)'))
  593. end)
  594. it('near the start', function()
  595. feed('<C-R>r<C-B><C-O>')
  596. screen:expect([[
  597. {7: 1 } |
  598. {7: 2 } |
  599. {7: 3 } |
  600. {7: 4 } |
  601. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  602. {7: 6 }:a{1:a}aaaaaa |
  603. {3:-- TERMINAL --} |
  604. ]])
  605. eq({6, 2}, eval('nvim_win_get_cursor(0)'))
  606. feed([[<C-\><C-N>]])
  607. screen:expect([[
  608. {7: 1 } |
  609. {7: 2 } |
  610. {7: 3 } |
  611. {7: 4 } |
  612. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  613. {7: 6 }:^a{2:a}aaaaaa |
  614. |
  615. ]])
  616. eq({6, 1}, eval('nvim_win_get_cursor(0)'))
  617. end)
  618. end)
  619. describe('in a line with single-cell multibyte characters and no trailing spaces,', function()
  620. before_each(function()
  621. setup_ex_register('µµµµµµµµ')
  622. end)
  623. it('at the end', function()
  624. feed('<C-R>r')
  625. screen:expect([[
  626. {7: 1 } |
  627. {7: 2 } |
  628. {7: 3 } |
  629. {7: 4 } |
  630. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  631. {7: 6 }:µµµµµµµµ{1: } |
  632. {3:-- TERMINAL --} |
  633. ]])
  634. eq({6, 17}, eval('nvim_win_get_cursor(0)'))
  635. feed([[<C-\><C-N>]])
  636. screen:expect([[
  637. {7: 1 } |
  638. {7: 2 } |
  639. {7: 3 } |
  640. {7: 4 } |
  641. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  642. {7: 6 }:µµµµµµµ^µ{2: } |
  643. |
  644. ]])
  645. eq({6, 15}, eval('nvim_win_get_cursor(0)'))
  646. end)
  647. it('near the end', function()
  648. feed('<C-R>r<C-X><C-X>')
  649. screen:expect([[
  650. {7: 1 } |
  651. {7: 2 } |
  652. {7: 3 } |
  653. {7: 4 } |
  654. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  655. {7: 6 }:µµµµµµ{1:µ}µ |
  656. {3:-- TERMINAL --} |
  657. ]])
  658. eq({6, 13}, eval('nvim_win_get_cursor(0)'))
  659. feed([[<C-\><C-N>]])
  660. screen:expect([[
  661. {7: 1 } |
  662. {7: 2 } |
  663. {7: 3 } |
  664. {7: 4 } |
  665. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  666. {7: 6 }:µµµµµ^µ{2:µ}µ |
  667. |
  668. ]])
  669. eq({6, 11}, eval('nvim_win_get_cursor(0)'))
  670. end)
  671. it('near the start', function()
  672. feed('<C-R>r<C-B><C-O>')
  673. screen:expect([[
  674. {7: 1 } |
  675. {7: 2 } |
  676. {7: 3 } |
  677. {7: 4 } |
  678. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  679. {7: 6 }:µ{1:µ}µµµµµµ |
  680. {3:-- TERMINAL --} |
  681. ]])
  682. eq({6, 3}, eval('nvim_win_get_cursor(0)'))
  683. feed([[<C-\><C-N>]])
  684. screen:expect([[
  685. {7: 1 } |
  686. {7: 2 } |
  687. {7: 3 } |
  688. {7: 4 } |
  689. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  690. {7: 6 }:^µ{2:µ}µµµµµµ |
  691. |
  692. ]])
  693. eq({6, 1}, eval('nvim_win_get_cursor(0)'))
  694. end)
  695. end)
  696. describe('in a line with single-cell composed multibyte characters and no trailing spaces,', function()
  697. if helpers.pending_win32(pending) then return end -- These tests fail on Windows. Encoding problem?
  698. before_each(function()
  699. setup_ex_register('µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳')
  700. end)
  701. it('at the end', function()
  702. feed('<C-R>r')
  703. screen:expect([[
  704. {7: 1 } |
  705. {7: 2 } |
  706. {7: 3 } |
  707. {7: 4 } |
  708. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  709. {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1: } |
  710. {3:-- TERMINAL --} |
  711. ]])
  712. eq({6, 33}, eval('nvim_win_get_cursor(0)'))
  713. feed([[<C-\><C-N>]])
  714. screen:expect([[
  715. {7: 1 } |
  716. {7: 2 } |
  717. {7: 3 } |
  718. {7: 4 } |
  719. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  720. {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳µ̳^µ̳{2: } |
  721. |
  722. ]])
  723. eq({6, 29}, eval('nvim_win_get_cursor(0)'))
  724. end)
  725. it('near the end', function()
  726. feed('<C-R>r<C-X><C-X>')
  727. screen:expect([[
  728. {7: 1 } |
  729. {7: 2 } |
  730. {7: 3 } |
  731. {7: 4 } |
  732. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  733. {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳{1:µ̳}µ̳ |
  734. {3:-- TERMINAL --} |
  735. ]])
  736. eq({6, 25}, eval('nvim_win_get_cursor(0)'))
  737. feed([[<C-\><C-N>]])
  738. screen:expect([[
  739. {7: 1 } |
  740. {7: 2 } |
  741. {7: 3 } |
  742. {7: 4 } |
  743. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  744. {7: 6 }:µ̳µ̳µ̳µ̳µ̳^µ̳{2:µ̳}µ̳ |
  745. |
  746. ]])
  747. eq({6, 21}, eval('nvim_win_get_cursor(0)'))
  748. end)
  749. it('near the start', function()
  750. feed('<C-R>r<C-B><C-O>')
  751. screen:expect([[
  752. {7: 1 } |
  753. {7: 2 } |
  754. {7: 3 } |
  755. {7: 4 } |
  756. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  757. {7: 6 }:µ̳{1:µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ |
  758. {3:-- TERMINAL --} |
  759. ]])
  760. eq({6, 5}, eval('nvim_win_get_cursor(0)'))
  761. feed([[<C-\><C-N>]])
  762. screen:expect([[
  763. {7: 1 } |
  764. {7: 2 } |
  765. {7: 3 } |
  766. {7: 4 } |
  767. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  768. {7: 6 }:^µ̳{2:µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ |
  769. |
  770. ]])
  771. eq({6, 1}, eval('nvim_win_get_cursor(0)'))
  772. end)
  773. end)
  774. describe('in a line with double-cell multibyte characters and no trailing spaces,', function()
  775. if helpers.pending_win32(pending) then return end -- These tests fail on Windows. Encoding problem?
  776. before_each(function()
  777. setup_ex_register('哦哦哦哦哦哦哦哦')
  778. end)
  779. it('at the end', function()
  780. feed('<C-R>r')
  781. screen:expect([[
  782. {7: 1 } |
  783. {7: 2 } |
  784. {7: 3 } |
  785. {7: 4 } |
  786. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  787. {7: 6 }:哦哦哦哦哦哦哦哦{1: } |
  788. {3:-- TERMINAL --} |
  789. ]])
  790. eq({6, 25}, eval('nvim_win_get_cursor(0)'))
  791. feed([[<C-\><C-N>]])
  792. screen:expect([[
  793. {7: 1 } |
  794. {7: 2 } |
  795. {7: 3 } |
  796. {7: 4 } |
  797. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  798. {7: 6 }:哦哦哦哦哦哦哦^哦{2: } |
  799. |
  800. ]])
  801. eq({6, 22}, eval('nvim_win_get_cursor(0)'))
  802. end)
  803. it('near the end', function()
  804. feed('<C-R>r<C-X><C-X>')
  805. screen:expect([[
  806. {7: 1 } |
  807. {7: 2 } |
  808. {7: 3 } |
  809. {7: 4 } |
  810. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  811. {7: 6 }:哦哦哦哦哦哦{1:哦}哦 |
  812. {3:-- TERMINAL --} |
  813. ]])
  814. eq({6, 19}, eval('nvim_win_get_cursor(0)'))
  815. feed([[<C-\><C-N>]])
  816. screen:expect([[
  817. {7: 1 } |
  818. {7: 2 } |
  819. {7: 3 } |
  820. {7: 4 } |
  821. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  822. {7: 6 }:哦哦哦哦哦^哦{2:哦}哦 |
  823. |
  824. ]])
  825. eq({6, 16}, eval('nvim_win_get_cursor(0)'))
  826. end)
  827. it('near the start', function()
  828. feed('<C-R>r<C-B><C-O>')
  829. screen:expect([[
  830. {7: 1 } |
  831. {7: 2 } |
  832. {7: 3 } |
  833. {7: 4 } |
  834. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  835. {7: 6 }:哦{1:哦}哦哦哦哦哦哦 |
  836. {3:-- TERMINAL --} |
  837. ]])
  838. eq({6, 4}, eval('nvim_win_get_cursor(0)'))
  839. feed([[<C-\><C-N>]])
  840. screen:expect([[
  841. {7: 1 } |
  842. {7: 2 } |
  843. {7: 3 } |
  844. {7: 4 } |
  845. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  846. {7: 6 }:^哦{2:哦}哦哦哦哦哦哦 |
  847. |
  848. ]])
  849. eq({6, 1}, eval('nvim_win_get_cursor(0)'))
  850. end)
  851. end)
  852. it('at the end of a line with trailing spaces #16234', function()
  853. setup_ex_register('aaaaaaaa ')
  854. feed('<C-R>r')
  855. screen:expect([[
  856. {7: 1 } |
  857. {7: 2 } |
  858. {7: 3 } |
  859. {7: 4 } |
  860. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  861. {7: 6 }:aaaaaaaa {1: } |
  862. {3:-- TERMINAL --} |
  863. ]])
  864. matches('^:aaaaaaaa [ ]*$', eval('nvim_get_current_line()'))
  865. eq({6, 13}, eval('nvim_win_get_cursor(0)'))
  866. feed([[<C-\><C-N>]])
  867. screen:expect([[
  868. {7: 1 } |
  869. {7: 2 } |
  870. {7: 3 } |
  871. {7: 4 } |
  872. {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
  873. {7: 6 }:aaaaaaaa ^ {2: } |
  874. |
  875. ]])
  876. eq({6, 12}, eval('nvim_win_get_cursor(0)'))
  877. end)
  878. end)