extmark_spec.lua 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local request = n.request
  5. local eq = t.eq
  6. local ok = t.ok
  7. local pcall_err = t.pcall_err
  8. local insert = n.insert
  9. local feed = n.feed
  10. local clear = n.clear
  11. local command = n.command
  12. local exec = n.exec
  13. local api = n.api
  14. local assert_alive = n.assert_alive
  15. local function expect(contents)
  16. return eq(contents, n.curbuf_contents())
  17. end
  18. local function set_extmark(ns_id, id, line, col, opts)
  19. if opts == nil then
  20. opts = {}
  21. end
  22. if id ~= nil and id ~= 0 then
  23. opts.id = id
  24. end
  25. return api.nvim_buf_set_extmark(0, ns_id, line, col, opts)
  26. end
  27. local function get_extmarks(ns_id, start, end_, opts)
  28. if opts == nil then
  29. opts = {}
  30. end
  31. return api.nvim_buf_get_extmarks(0, ns_id, start, end_, opts)
  32. end
  33. local function get_extmark_by_id(ns_id, id, opts)
  34. if opts == nil then
  35. opts = {}
  36. end
  37. return api.nvim_buf_get_extmark_by_id(0, ns_id, id, opts)
  38. end
  39. local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
  40. local rv = get_extmark_by_id(ns, mark)
  41. eq({ er, ec }, rv)
  42. feed('u')
  43. rv = get_extmark_by_id(ns, mark)
  44. eq({ sr, sc }, rv)
  45. feed('<c-r>')
  46. rv = get_extmark_by_id(ns, mark)
  47. eq({ er, ec }, rv)
  48. end
  49. local function batch_set(ns_id, positions)
  50. local ids = {}
  51. for _, pos in ipairs(positions) do
  52. table.insert(ids, set_extmark(ns_id, 0, pos[1], pos[2]))
  53. end
  54. return ids
  55. end
  56. local function batch_check(ns_id, ids, positions)
  57. local actual, expected = {}, {}
  58. for i, id in ipairs(ids) do
  59. expected[id] = positions[i]
  60. end
  61. for _, mark in pairs(get_extmarks(ns_id, 0, -1, {})) do
  62. actual[mark[1]] = { mark[2], mark[3] }
  63. end
  64. eq(expected, actual)
  65. end
  66. local function batch_check_undo_redo(ns_id, ids, before, after)
  67. batch_check(ns_id, ids, after)
  68. feed('u')
  69. batch_check(ns_id, ids, before)
  70. feed('<c-r>')
  71. batch_check(ns_id, ids, after)
  72. end
  73. describe('API/extmarks', function()
  74. local screen
  75. local marks, positions, init_text, row, col
  76. local ns, ns2
  77. before_each(function()
  78. -- Initialize some namespaces and insert 12345 into a buffer
  79. marks = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
  80. positions = { { 0, 0 }, { 0, 2 }, { 0, 3 } }
  81. init_text = '12345'
  82. row = 0
  83. col = 2
  84. clear()
  85. insert(init_text)
  86. ns = request('nvim_create_namespace', 'my-fancy-plugin')
  87. ns2 = request('nvim_create_namespace', 'my-fancy-plugin2')
  88. end)
  89. it('validation', function()
  90. eq(
  91. "Invalid 'end_col': expected Integer, got Array",
  92. pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = {}, end_row = 1 })
  93. )
  94. eq(
  95. "Invalid 'end_row': expected Integer, got Array",
  96. pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = {} })
  97. )
  98. eq(
  99. "Invalid 'virt_text_pos': expected String, got Integer",
  100. pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 0 })
  101. )
  102. eq(
  103. "Invalid 'virt_text_pos': 'foo'",
  104. pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 'foo' })
  105. )
  106. eq(
  107. "Invalid 'hl_mode': expected String, got Integer",
  108. pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 0 })
  109. )
  110. eq("Invalid 'hl_mode': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 'foo' }))
  111. eq(
  112. "Invalid 'id': expected Integer, got Array",
  113. pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 })
  114. )
  115. eq(
  116. 'Invalid mark position: expected 2 Integer items',
  117. pcall_err(get_extmarks, ns, {}, { -1, -1 })
  118. )
  119. eq(
  120. 'Invalid mark position: expected mark id Integer or 2-item Array',
  121. pcall_err(get_extmarks, ns, true, { -1, -1 })
  122. )
  123. -- No memory leak with virt_text, virt_lines, sign_text
  124. eq(
  125. 'right_gravity is not a boolean',
  126. pcall_err(set_extmark, ns, marks[2], 0, 0, {
  127. virt_text = { { 'foo', 'Normal' } },
  128. virt_lines = { { { 'bar', 'Normal' } } },
  129. sign_text = 'a',
  130. right_gravity = 'baz',
  131. })
  132. )
  133. end)
  134. it('can end extranges past final newline using end_col = 0', function()
  135. set_extmark(ns, marks[1], 0, 0, {
  136. end_col = 0,
  137. end_row = 1,
  138. })
  139. eq(
  140. "Invalid 'end_col': out of range",
  141. pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = 1 })
  142. )
  143. end)
  144. it('can end extranges past final newline when strict mode is false', function()
  145. set_extmark(ns, marks[1], 0, 0, {
  146. end_col = 1,
  147. end_row = 1,
  148. strict = false,
  149. })
  150. end)
  151. it('can end extranges past final column when strict mode is false', function()
  152. set_extmark(ns, marks[1], 0, 0, {
  153. end_col = 6,
  154. end_row = 0,
  155. strict = false,
  156. })
  157. end)
  158. it('adds, updates and deletes marks', function()
  159. local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
  160. eq(marks[1], rv)
  161. rv = get_extmark_by_id(ns, marks[1])
  162. eq({ positions[1][1], positions[1][2] }, rv)
  163. -- Test adding a second mark on same row works
  164. rv = set_extmark(ns, marks[2], positions[2][1], positions[2][2])
  165. eq(marks[2], rv)
  166. -- Test an update, (same pos)
  167. rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
  168. eq(marks[1], rv)
  169. rv = get_extmark_by_id(ns, marks[2])
  170. eq({ positions[2][1], positions[2][2] }, rv)
  171. -- Test an update, (new pos)
  172. row = positions[1][1]
  173. col = positions[1][2] + 1
  174. rv = set_extmark(ns, marks[1], row, col)
  175. eq(marks[1], rv)
  176. rv = get_extmark_by_id(ns, marks[1])
  177. eq({ row, col }, rv)
  178. -- remove the test marks
  179. eq(true, api.nvim_buf_del_extmark(0, ns, marks[1]))
  180. eq(false, api.nvim_buf_del_extmark(0, ns, marks[1]))
  181. eq(true, api.nvim_buf_del_extmark(0, ns, marks[2]))
  182. eq(false, api.nvim_buf_del_extmark(0, ns, marks[3]))
  183. eq(false, api.nvim_buf_del_extmark(0, ns, 1000))
  184. end)
  185. it('can clear a specific namespace range', function()
  186. set_extmark(ns, 1, 0, 1)
  187. set_extmark(ns2, 1, 0, 1)
  188. -- force a new undo buffer
  189. feed('o<esc>')
  190. api.nvim_buf_clear_namespace(0, ns2, 0, -1)
  191. eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
  192. eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
  193. feed('u')
  194. eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
  195. eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
  196. feed('<c-r>')
  197. eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
  198. eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
  199. end)
  200. it('can clear a namespace range using 0,-1', function()
  201. set_extmark(ns, 1, 0, 1)
  202. set_extmark(ns2, 1, 0, 1)
  203. -- force a new undo buffer
  204. feed('o<esc>')
  205. api.nvim_buf_clear_namespace(0, -1, 0, -1)
  206. eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
  207. eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
  208. feed('u')
  209. eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
  210. eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
  211. feed('<c-r>')
  212. eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
  213. eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
  214. end)
  215. it('can undo with extmarks (#25147)', function()
  216. feed('itest<esc>')
  217. set_extmark(ns, 1, 0, 0)
  218. set_extmark(ns, 2, 1, 0)
  219. eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
  220. feed('dd')
  221. eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
  222. api.nvim_buf_clear_namespace(0, ns, 0, -1)
  223. eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
  224. set_extmark(ns, 1, 0, 0, { right_gravity = false })
  225. set_extmark(ns, 2, 1, 0, { right_gravity = false })
  226. eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
  227. feed('u')
  228. eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
  229. api.nvim_buf_clear_namespace(0, ns, 0, -1)
  230. end)
  231. it('querying for information and ranges', function()
  232. --marks = {1, 2, 3}
  233. --positions = {{0, 0,}, {0, 2}, {0, 3}}
  234. -- add some more marks
  235. for i, m in ipairs(marks) do
  236. if positions[i] ~= nil then
  237. local rv = set_extmark(ns, m, positions[i][1], positions[i][2])
  238. eq(m, rv)
  239. end
  240. end
  241. -- {0, 0} and {-1, -1} work as extreme values
  242. eq({ { 1, 0, 0 } }, get_extmarks(ns, { 0, 0 }, { 0, 0 }))
  243. eq({}, get_extmarks(ns, { -1, -1 }, { -1, -1 }))
  244. local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
  245. for i, m in ipairs(marks) do
  246. if positions[i] ~= nil then
  247. eq({ m, positions[i][1], positions[i][2] }, rv[i])
  248. end
  249. end
  250. -- 0 and -1 works as short hand extreme values
  251. eq({ { 1, 0, 0 } }, get_extmarks(ns, 0, 0))
  252. eq({}, get_extmarks(ns, -1, -1))
  253. rv = get_extmarks(ns, 0, -1)
  254. for i, m in ipairs(marks) do
  255. if positions[i] ~= nil then
  256. eq({ m, positions[i][1], positions[i][2] }, rv[i])
  257. end
  258. end
  259. -- next with mark id
  260. rv = get_extmarks(ns, marks[1], { -1, -1 }, { limit = 1 })
  261. eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
  262. rv = get_extmarks(ns, marks[2], { -1, -1 }, { limit = 1 })
  263. eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
  264. -- next with positional when mark exists at position
  265. rv = get_extmarks(ns, positions[1], { -1, -1 }, { limit = 1 })
  266. eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
  267. -- next with positional index (no mark at position)
  268. rv = get_extmarks(ns, { positions[1][1], positions[1][2] + 1 }, { -1, -1 }, { limit = 1 })
  269. eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
  270. -- next with Extremity index
  271. rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 })
  272. eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
  273. -- nextrange with mark id
  274. rv = get_extmarks(ns, marks[1], marks[3])
  275. eq({ marks[1], positions[1][1], positions[1][2] }, rv[1])
  276. eq({ marks[2], positions[2][1], positions[2][2] }, rv[2])
  277. -- nextrange with `limit`
  278. rv = get_extmarks(ns, marks[1], marks[3], { limit = 2 })
  279. eq(2, #rv)
  280. -- nextrange with positional when mark exists at position
  281. rv = get_extmarks(ns, positions[1], positions[3])
  282. eq({ marks[1], positions[1][1], positions[1][2] }, rv[1])
  283. eq({ marks[2], positions[2][1], positions[2][2] }, rv[2])
  284. rv = get_extmarks(ns, positions[2], positions[3])
  285. eq(2, #rv)
  286. -- nextrange with positional index (no mark at position)
  287. local lower = { positions[1][1], positions[2][2] - 1 }
  288. local upper = { positions[2][1], positions[3][2] - 1 }
  289. rv = get_extmarks(ns, lower, upper)
  290. eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
  291. lower = { positions[3][1], positions[3][2] + 1 }
  292. upper = { positions[3][1], positions[3][2] + 2 }
  293. rv = get_extmarks(ns, lower, upper)
  294. eq({}, rv)
  295. -- nextrange with extremity index
  296. lower = { positions[2][1], positions[2][2] + 1 }
  297. upper = { -1, -1 }
  298. rv = get_extmarks(ns, lower, upper)
  299. eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
  300. -- prev with mark id
  301. rv = get_extmarks(ns, marks[3], { 0, 0 }, { limit = 1 })
  302. eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
  303. rv = get_extmarks(ns, marks[2], { 0, 0 }, { limit = 1 })
  304. eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
  305. -- prev with positional when mark exists at position
  306. rv = get_extmarks(ns, positions[3], { 0, 0 }, { limit = 1 })
  307. eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
  308. -- prev with positional index (no mark at position)
  309. rv = get_extmarks(ns, { positions[1][1], positions[1][2] + 1 }, { 0, 0 }, { limit = 1 })
  310. eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
  311. -- prev with Extremity index
  312. rv = get_extmarks(ns, { -1, -1 }, { 0, 0 }, { limit = 1 })
  313. eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
  314. -- prevrange with mark id
  315. rv = get_extmarks(ns, marks[3], marks[1])
  316. eq({ marks[3], positions[3][1], positions[3][2] }, rv[1])
  317. eq({ marks[2], positions[2][1], positions[2][2] }, rv[2])
  318. eq({ marks[1], positions[1][1], positions[1][2] }, rv[3])
  319. -- prevrange with limit
  320. rv = get_extmarks(ns, marks[3], marks[1], { limit = 2 })
  321. eq(2, #rv)
  322. -- prevrange with positional when mark exists at position
  323. rv = get_extmarks(ns, positions[3], positions[1])
  324. eq({
  325. { marks[3], positions[3][1], positions[3][2] },
  326. { marks[2], positions[2][1], positions[2][2] },
  327. { marks[1], positions[1][1], positions[1][2] },
  328. }, rv)
  329. rv = get_extmarks(ns, positions[2], positions[1])
  330. eq(2, #rv)
  331. -- prevrange with positional index (no mark at position)
  332. lower = { positions[2][1], positions[2][2] + 1 }
  333. upper = { positions[3][1], positions[3][2] + 1 }
  334. rv = get_extmarks(ns, upper, lower)
  335. eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
  336. lower = { positions[3][1], positions[3][2] + 1 }
  337. upper = { positions[3][1], positions[3][2] + 2 }
  338. rv = get_extmarks(ns, upper, lower)
  339. eq({}, rv)
  340. -- prevrange with extremity index
  341. lower = { 0, 0 }
  342. upper = { positions[2][1], positions[2][2] - 1 }
  343. rv = get_extmarks(ns, upper, lower)
  344. eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
  345. end)
  346. it('querying for information with limit', function()
  347. -- add some more marks
  348. for i, m in ipairs(marks) do
  349. if positions[i] ~= nil then
  350. local rv = set_extmark(ns, m, positions[i][1], positions[i][2])
  351. eq(m, rv)
  352. end
  353. end
  354. local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 })
  355. eq(1, #rv)
  356. rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 2 })
  357. eq(2, #rv)
  358. rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 3 })
  359. eq(3, #rv)
  360. -- now in reverse
  361. rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 })
  362. eq(1, #rv)
  363. rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 2 })
  364. eq(2, #rv)
  365. rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 3 })
  366. eq(3, #rv)
  367. end)
  368. it('get_marks works when mark col > upper col', function()
  369. feed('A<cr>12345<esc>')
  370. feed('A<cr>12345<esc>')
  371. set_extmark(ns, 10, 0, 2) -- this shouldn't be found
  372. set_extmark(ns, 11, 2, 1) -- this shouldn't be found
  373. set_extmark(ns, marks[1], 0, 4) -- check col > our upper bound
  374. set_extmark(ns, marks[2], 1, 1) -- check col < lower bound
  375. set_extmark(ns, marks[3], 2, 0) -- check is inclusive
  376. eq(
  377. { { marks[1], 0, 4 }, { marks[2], 1, 1 }, { marks[3], 2, 0 } },
  378. get_extmarks(ns, { 0, 3 }, { 2, 0 })
  379. )
  380. end)
  381. it('get_marks works in reverse when mark col < lower col', function()
  382. feed('A<cr>12345<esc>')
  383. feed('A<cr>12345<esc>')
  384. set_extmark(ns, 10, 0, 1) -- this shouldn't be found
  385. set_extmark(ns, 11, 2, 4) -- this shouldn't be found
  386. set_extmark(ns, marks[1], 2, 1) -- check col < our lower bound
  387. set_extmark(ns, marks[2], 1, 4) -- check col > upper bound
  388. set_extmark(ns, marks[3], 0, 2) -- check is inclusive
  389. local rv = get_extmarks(ns, { 2, 3 }, { 0, 2 })
  390. eq({ { marks[1], 2, 1 }, { marks[2], 1, 4 }, { marks[3], 0, 2 } }, rv)
  391. end)
  392. it('get_marks limit=0 returns nothing', function()
  393. set_extmark(ns, marks[1], positions[1][1], positions[1][2])
  394. local rv = get_extmarks(ns, { -1, -1 }, { -1, -1 }, { limit = 0 })
  395. eq({}, rv)
  396. end)
  397. it('marks move with line insertations', function()
  398. set_extmark(ns, marks[1], 0, 0)
  399. feed('yyP')
  400. check_undo_redo(ns, marks[1], 0, 0, 1, 0)
  401. end)
  402. it('marks move with multiline insertations', function()
  403. feed('a<cr>22<cr>33<esc>')
  404. set_extmark(ns, marks[1], 1, 1)
  405. feed('ggVGyP')
  406. check_undo_redo(ns, marks[1], 1, 1, 4, 1)
  407. end)
  408. it('marks move with line join', function()
  409. -- do_join in ops.c
  410. feed('a<cr>222<esc>')
  411. set_extmark(ns, marks[1], 1, 0)
  412. feed('ggJ')
  413. check_undo_redo(ns, marks[1], 1, 0, 0, 6)
  414. end)
  415. it('join works when no marks are present', function()
  416. screen = Screen.new(15, 10)
  417. feed('a<cr>1<esc>')
  418. feed('kJ')
  419. -- This shouldn't seg fault
  420. screen:expect([[
  421. 12345^ 1 |
  422. {1:~ }|*8
  423. |
  424. ]])
  425. end)
  426. it('marks move with multiline join', function()
  427. -- do_join in ops.c
  428. feed('a<cr>222<cr>333<cr>444<esc>')
  429. set_extmark(ns, marks[1], 3, 0)
  430. feed('2GVGJ')
  431. check_undo_redo(ns, marks[1], 3, 0, 1, 8)
  432. end)
  433. it('marks move with line deletes', function()
  434. feed('a<cr>222<cr>333<cr>444<esc>')
  435. set_extmark(ns, marks[1], 2, 1)
  436. feed('ggjdd')
  437. check_undo_redo(ns, marks[1], 2, 1, 1, 1)
  438. end)
  439. it('marks move with multiline deletes', function()
  440. feed('a<cr>222<cr>333<cr>444<esc>')
  441. set_extmark(ns, marks[1], 3, 0)
  442. feed('gg2dd')
  443. check_undo_redo(ns, marks[1], 3, 0, 1, 0)
  444. -- regression test, undoing multiline delete when mark is on row 1
  445. feed('ugg3dd')
  446. check_undo_redo(ns, marks[1], 3, 0, 0, 0)
  447. end)
  448. it('marks move with open line', function()
  449. -- open_line in change.c
  450. -- testing marks below are also moved
  451. feed('yyP')
  452. set_extmark(ns, marks[1], 0, 4)
  453. set_extmark(ns, marks[2], 1, 4)
  454. feed('1G<s-o><esc>')
  455. check_undo_redo(ns, marks[1], 0, 4, 1, 4)
  456. check_undo_redo(ns, marks[2], 1, 4, 2, 4)
  457. feed('2Go<esc>')
  458. check_undo_redo(ns, marks[1], 1, 4, 1, 4)
  459. check_undo_redo(ns, marks[2], 2, 4, 3, 4)
  460. end)
  461. it('marks move with char inserts', function()
  462. -- insertchar in edit.c (the ins_str branch)
  463. screen = Screen.new(15, 10)
  464. set_extmark(ns, marks[1], 0, 3)
  465. feed('0')
  466. insert('abc')
  467. screen:expect([[
  468. ab^c12345 |
  469. {1:~ }|*8
  470. |
  471. ]])
  472. local rv = get_extmark_by_id(ns, marks[1])
  473. eq({ 0, 6 }, rv)
  474. check_undo_redo(ns, marks[1], 0, 3, 0, 6)
  475. end)
  476. -- gravity right as definted in tk library
  477. it('marks have gravity right', function()
  478. -- insertchar in edit.c (the ins_str branch)
  479. set_extmark(ns, marks[1], 0, 2)
  480. feed('03l')
  481. insert('X')
  482. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  483. -- check multibyte chars
  484. feed('03l<esc>')
  485. insert('~~')
  486. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  487. end)
  488. it('we can insert multibyte chars', function()
  489. -- insertchar in edit.c
  490. feed('a<cr>12345<esc>')
  491. set_extmark(ns, marks[1], 1, 2)
  492. -- Insert a fullwidth (two col) tilde, NICE
  493. feed('0i~<esc>')
  494. check_undo_redo(ns, marks[1], 1, 2, 1, 5)
  495. end)
  496. it('marks move with blockwise inserts', function()
  497. -- op_insert in ops.c
  498. feed('a<cr>12345<esc>')
  499. set_extmark(ns, marks[1], 1, 2)
  500. feed('0<c-v>lkI9<esc>')
  501. check_undo_redo(ns, marks[1], 1, 2, 1, 3)
  502. end)
  503. it('marks move with line splits (using enter)', function()
  504. -- open_line in change.c
  505. -- testing marks below are also moved
  506. feed('yyP')
  507. set_extmark(ns, marks[1], 0, 4)
  508. set_extmark(ns, marks[2], 1, 4)
  509. feed('1Gla<cr><esc>')
  510. check_undo_redo(ns, marks[1], 0, 4, 1, 2)
  511. check_undo_redo(ns, marks[2], 1, 4, 2, 4)
  512. end)
  513. it('marks at last line move on insert new line', function()
  514. -- open_line in change.c
  515. set_extmark(ns, marks[1], 0, 4)
  516. feed('0i<cr><esc>')
  517. check_undo_redo(ns, marks[1], 0, 4, 1, 4)
  518. end)
  519. it('yet again marks move with line splits', function()
  520. -- the first test above wasn't catching all errors..
  521. feed('A67890<esc>')
  522. set_extmark(ns, marks[1], 0, 4)
  523. feed('04li<cr><esc>')
  524. check_undo_redo(ns, marks[1], 0, 4, 1, 0)
  525. end)
  526. it('and one last time line splits...', function()
  527. set_extmark(ns, marks[1], 0, 1)
  528. set_extmark(ns, marks[2], 0, 2)
  529. feed('02li<cr><esc>')
  530. check_undo_redo(ns, marks[1], 0, 1, 0, 1)
  531. check_undo_redo(ns, marks[2], 0, 2, 1, 0)
  532. end)
  533. it('multiple marks move with mark splits', function()
  534. set_extmark(ns, marks[1], 0, 1)
  535. set_extmark(ns, marks[2], 0, 3)
  536. feed('0li<cr><esc>')
  537. check_undo_redo(ns, marks[1], 0, 1, 1, 0)
  538. check_undo_redo(ns, marks[2], 0, 3, 1, 2)
  539. end)
  540. it('deleting right before a mark works', function()
  541. -- op_delete in ops.c
  542. set_extmark(ns, marks[1], 0, 2)
  543. feed('0lx')
  544. check_undo_redo(ns, marks[1], 0, 2, 0, 1)
  545. end)
  546. it('deleting right after a mark works', function()
  547. -- op_delete in ops.c
  548. set_extmark(ns, marks[1], 0, 2)
  549. feed('02lx')
  550. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  551. end)
  552. it('marks move with char deletes', function()
  553. -- op_delete in ops.c
  554. set_extmark(ns, marks[1], 0, 2)
  555. feed('02dl')
  556. check_undo_redo(ns, marks[1], 0, 2, 0, 0)
  557. -- from the other side (nothing should happen)
  558. feed('$x')
  559. check_undo_redo(ns, marks[1], 0, 0, 0, 0)
  560. end)
  561. it('marks move with char deletes over a range', function()
  562. -- op_delete in ops.c
  563. set_extmark(ns, marks[1], 0, 2)
  564. set_extmark(ns, marks[2], 0, 3)
  565. feed('0l3dl<esc>')
  566. check_undo_redo(ns, marks[1], 0, 2, 0, 1)
  567. check_undo_redo(ns, marks[2], 0, 3, 0, 1)
  568. -- delete 1, nothing should happen to our marks
  569. feed('u')
  570. feed('$x')
  571. check_undo_redo(ns, marks[2], 0, 3, 0, 3)
  572. end)
  573. it('deleting marks at end of line works', function()
  574. set_extmark(ns, marks[1], 0, 4)
  575. feed('$x')
  576. check_undo_redo(ns, marks[1], 0, 4, 0, 4)
  577. -- check the copy happened correctly on delete at eol
  578. feed('$x')
  579. check_undo_redo(ns, marks[1], 0, 4, 0, 3)
  580. feed('u')
  581. check_undo_redo(ns, marks[1], 0, 4, 0, 4)
  582. end)
  583. it('marks move with blockwise deletes', function()
  584. -- op_delete in ops.c
  585. feed('a<cr>12345<esc>')
  586. set_extmark(ns, marks[1], 1, 4)
  587. feed('h<c-v>hhkd')
  588. check_undo_redo(ns, marks[1], 1, 4, 1, 1)
  589. end)
  590. it('marks move with blockwise deletes over a range', function()
  591. -- op_delete in ops.c
  592. feed('a<cr>12345<esc>')
  593. set_extmark(ns, marks[1], 0, 1)
  594. set_extmark(ns, marks[2], 0, 3)
  595. set_extmark(ns, marks[3], 1, 2)
  596. feed('0<c-v>k3lx')
  597. check_undo_redo(ns, marks[1], 0, 1, 0, 0)
  598. check_undo_redo(ns, marks[2], 0, 3, 0, 0)
  599. check_undo_redo(ns, marks[3], 1, 2, 1, 0)
  600. -- delete 1, nothing should happen to our marks
  601. feed('u')
  602. feed('$<c-v>jx')
  603. check_undo_redo(ns, marks[2], 0, 3, 0, 3)
  604. check_undo_redo(ns, marks[3], 1, 2, 1, 2)
  605. end)
  606. it('works with char deletes over multilines', function()
  607. feed('a<cr>12345<cr>test-me<esc>')
  608. set_extmark(ns, marks[1], 2, 5)
  609. feed('gg')
  610. feed('dv?-m?<cr>')
  611. check_undo_redo(ns, marks[1], 2, 5, 0, 0)
  612. end)
  613. it('marks outside of deleted range move with visual char deletes', function()
  614. -- op_delete in ops.c
  615. set_extmark(ns, marks[1], 0, 3)
  616. feed('0vx<esc>')
  617. check_undo_redo(ns, marks[1], 0, 3, 0, 2)
  618. feed('u')
  619. feed('0vlx<esc>')
  620. check_undo_redo(ns, marks[1], 0, 3, 0, 1)
  621. feed('u')
  622. feed('0v2lx<esc>')
  623. check_undo_redo(ns, marks[1], 0, 3, 0, 0)
  624. -- from the other side (nothing should happen)
  625. feed('$vx')
  626. check_undo_redo(ns, marks[1], 0, 0, 0, 0)
  627. end)
  628. it('marks outside of deleted range move with char deletes', function()
  629. -- op_delete in ops.c
  630. set_extmark(ns, marks[1], 0, 3)
  631. feed('0x<esc>')
  632. check_undo_redo(ns, marks[1], 0, 3, 0, 2)
  633. feed('u')
  634. feed('02x<esc>')
  635. check_undo_redo(ns, marks[1], 0, 3, 0, 1)
  636. feed('u')
  637. feed('0v3lx<esc>')
  638. check_undo_redo(ns, marks[1], 0, 3, 0, 0)
  639. -- from the other side (nothing should happen)
  640. feed('u')
  641. feed('$vx')
  642. check_undo_redo(ns, marks[1], 0, 3, 0, 3)
  643. end)
  644. it('marks move with P(backward) paste', function()
  645. -- do_put in ops.c
  646. feed('0iabc<esc>')
  647. set_extmark(ns, marks[1], 0, 7)
  648. feed('0veyP')
  649. check_undo_redo(ns, marks[1], 0, 7, 0, 15)
  650. end)
  651. it('marks move with p(forward) paste', function()
  652. -- do_put in ops.c
  653. feed('0iabc<esc>')
  654. set_extmark(ns, marks[1], 0, 7)
  655. feed('0veyp')
  656. check_undo_redo(ns, marks[1], 0, 7, 0, 15)
  657. end)
  658. it('marks move with blockwise P(backward) paste', function()
  659. -- do_put in ops.c
  660. feed('a<cr>12345<esc>')
  661. set_extmark(ns, marks[1], 1, 4)
  662. feed('<c-v>hhkyP<esc>')
  663. check_undo_redo(ns, marks[1], 1, 4, 1, 7)
  664. end)
  665. it('marks move with blockwise p(forward) paste', function()
  666. -- do_put in ops.c
  667. feed('a<cr>12345<esc>')
  668. set_extmark(ns, marks[1], 1, 4)
  669. feed('<c-v>hhkyp<esc>')
  670. check_undo_redo(ns, marks[1], 1, 4, 1, 7)
  671. end)
  672. describe('multiline regions', function()
  673. before_each(function()
  674. feed('dd')
  675. -- Achtung: code has been spiced with some unicode,
  676. -- to make life more interesting.
  677. -- luacheck whines about TABs inside strings for whatever reason.
  678. -- luacheck: push ignore 621
  679. insert([[
  680. static int nlua_rpcrequest(lua_State *lstate)
  681. {
  682. Ïf (!nlua_is_deferred_safe(lstate)) {
  683. // strictly not allowed
  684. Яetörn luaL_error(lstate, e_fast_api_disabled, "rpcrequest");
  685. }
  686. return nlua_rpc(lstate, true);
  687. }]])
  688. -- luacheck: pop
  689. end)
  690. it('delete', function()
  691. local pos1 = {
  692. { 2, 4 },
  693. { 2, 12 },
  694. { 2, 13 },
  695. { 2, 14 },
  696. { 2, 25 },
  697. { 4, 8 },
  698. { 4, 10 },
  699. { 4, 20 },
  700. { 5, 3 },
  701. { 6, 10 },
  702. }
  703. local ids = batch_set(ns, pos1)
  704. batch_check(ns, ids, pos1)
  705. feed('3Gfiv2+ftd')
  706. batch_check_undo_redo(ns, ids, pos1, {
  707. { 2, 4 },
  708. { 2, 12 },
  709. { 2, 13 },
  710. { 2, 13 },
  711. { 2, 13 },
  712. { 2, 13 },
  713. { 2, 15 },
  714. { 2, 25 },
  715. { 3, 3 },
  716. { 4, 10 },
  717. })
  718. end)
  719. it('can get overlapping extmarks', function()
  720. set_extmark(ns, 1, 0, 0, { end_row = 5, end_col = 0 })
  721. set_extmark(ns, 2, 2, 5, { end_row = 2, end_col = 30 })
  722. set_extmark(ns, 3, 0, 5, { end_row = 2, end_col = 10 })
  723. set_extmark(ns, 4, 0, 0, { end_row = 1, end_col = 0 })
  724. eq({ { 2, 2, 5 } }, get_extmarks(ns, { 2, 0 }, { 2, -1 }, { overlap = false }))
  725. eq(
  726. { { 1, 0, 0 }, { 3, 0, 5 }, { 2, 2, 5 } },
  727. get_extmarks(ns, { 2, 0 }, { 2, -1 }, { overlap = true })
  728. )
  729. end)
  730. end)
  731. it('replace works', function()
  732. set_extmark(ns, marks[1], 0, 2)
  733. feed('0r2')
  734. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  735. end)
  736. it('blockwise replace works', function()
  737. feed('a<cr>12345<esc>')
  738. set_extmark(ns, marks[1], 0, 2)
  739. feed('0<c-v>llkr1<esc>')
  740. check_undo_redo(ns, marks[1], 0, 2, 0, 3)
  741. end)
  742. it('shift line', function()
  743. -- shift_line in ops.c
  744. feed(':set shiftwidth=4<cr><esc>')
  745. set_extmark(ns, marks[1], 0, 2)
  746. feed('0>>')
  747. check_undo_redo(ns, marks[1], 0, 2, 0, 6)
  748. expect(' 12345')
  749. feed('>>')
  750. -- this is counter-intuitive. But what happens
  751. -- is that 4 spaces gets extended to one tab (== 8 spaces)
  752. check_undo_redo(ns, marks[1], 0, 6, 0, 3)
  753. expect('\t12345')
  754. feed('<LT><LT>') -- have to escape, same as <<
  755. check_undo_redo(ns, marks[1], 0, 3, 0, 6)
  756. end)
  757. it('blockwise shift', function()
  758. -- shift_block in ops.c
  759. feed(':set shiftwidth=4<cr><esc>')
  760. feed('a<cr>12345<esc>')
  761. set_extmark(ns, marks[1], 1, 2)
  762. feed('0<c-v>k>')
  763. check_undo_redo(ns, marks[1], 1, 2, 1, 6)
  764. feed('<c-v>j>')
  765. expect('\t12345\n\t12345')
  766. check_undo_redo(ns, marks[1], 1, 6, 1, 3)
  767. feed('<c-v>j<LT>')
  768. check_undo_redo(ns, marks[1], 1, 3, 1, 6)
  769. end)
  770. it('tab works with expandtab', function()
  771. -- ins_tab in edit.c
  772. feed(':set expandtab<cr><esc>')
  773. feed(':set shiftwidth=2<cr><esc>')
  774. set_extmark(ns, marks[1], 0, 2)
  775. feed('0i<tab><tab><esc>')
  776. check_undo_redo(ns, marks[1], 0, 2, 0, 6)
  777. end)
  778. it('tabs work', function()
  779. -- ins_tab in edit.c
  780. feed(':set noexpandtab<cr><esc>')
  781. feed(':set shiftwidth=2<cr><esc>')
  782. feed(':set softtabstop=2<cr><esc>')
  783. feed(':set tabstop=8<cr><esc>')
  784. set_extmark(ns, marks[1], 0, 2)
  785. feed('0i<tab><esc>')
  786. check_undo_redo(ns, marks[1], 0, 2, 0, 4)
  787. feed('0iX<tab><esc>')
  788. check_undo_redo(ns, marks[1], 0, 4, 0, 6)
  789. end)
  790. it('marks move when using :move', function()
  791. set_extmark(ns, marks[1], 0, 0)
  792. feed('A<cr>2<esc>:1move 2<cr><esc>')
  793. check_undo_redo(ns, marks[1], 0, 0, 1, 0)
  794. -- test codepath when moving lines up
  795. feed(':2move 0<cr><esc>')
  796. check_undo_redo(ns, marks[1], 1, 0, 0, 0)
  797. end)
  798. it('marks move when using :move part 2', function()
  799. -- make sure we didn't get lucky with the math...
  800. feed('A<cr>2<cr>3<cr>4<cr>5<cr>6<esc>')
  801. set_extmark(ns, marks[1], 1, 0)
  802. feed(':2,3move 5<cr><esc>')
  803. check_undo_redo(ns, marks[1], 1, 0, 3, 0)
  804. -- test codepath when moving lines up
  805. feed(':4,5move 1<cr><esc>')
  806. check_undo_redo(ns, marks[1], 3, 0, 1, 0)
  807. end)
  808. it('undo and redo of set and unset marks', function()
  809. -- Force a new undo head
  810. feed('o<esc>')
  811. set_extmark(ns, marks[1], 0, 1)
  812. feed('o<esc>')
  813. set_extmark(ns, marks[2], 0, -1)
  814. set_extmark(ns, marks[3], 0, -1)
  815. feed('u')
  816. local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
  817. eq(3, #rv)
  818. feed('<c-r>')
  819. rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
  820. eq(3, #rv)
  821. -- Test updates
  822. feed('o<esc>')
  823. set_extmark(ns, marks[1], positions[1][1], positions[1][2])
  824. rv = get_extmarks(ns, marks[1], marks[1], { limit = 1 })
  825. eq(1, #rv)
  826. feed('u')
  827. feed('<c-r>')
  828. -- old value is NOT kept in history
  829. check_undo_redo(
  830. ns,
  831. marks[1],
  832. positions[1][1],
  833. positions[1][2],
  834. positions[1][1],
  835. positions[1][2]
  836. )
  837. -- Test unset
  838. feed('o<esc>')
  839. api.nvim_buf_del_extmark(0, ns, marks[3])
  840. feed('u')
  841. rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
  842. -- undo does NOT restore deleted marks
  843. eq(2, #rv)
  844. feed('<c-r>')
  845. rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
  846. eq(2, #rv)
  847. end)
  848. it('undo and redo of marks deleted during edits', function()
  849. -- test extmark_adjust
  850. feed('A<cr>12345<esc>')
  851. set_extmark(ns, marks[1], 1, 2)
  852. feed('dd')
  853. check_undo_redo(ns, marks[1], 1, 2, 1, 0)
  854. end)
  855. it('namespaces work properly', function()
  856. local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
  857. eq(1, rv)
  858. rv = set_extmark(ns2, marks[1], positions[1][1], positions[1][2])
  859. eq(1, rv)
  860. rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
  861. eq(1, #rv)
  862. rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 })
  863. eq(1, #rv)
  864. -- Set more marks for testing the ranges
  865. set_extmark(ns, marks[2], positions[2][1], positions[2][2])
  866. set_extmark(ns, marks[3], positions[3][1], positions[3][2])
  867. set_extmark(ns2, marks[2], positions[2][1], positions[2][2])
  868. set_extmark(ns2, marks[3], positions[3][1], positions[3][2])
  869. -- get_next (limit set)
  870. rv = get_extmarks(ns, { 0, 0 }, positions[2], { limit = 1 })
  871. eq(1, #rv)
  872. rv = get_extmarks(ns2, { 0, 0 }, positions[2], { limit = 1 })
  873. eq(1, #rv)
  874. -- get_prev (limit set)
  875. rv = get_extmarks(ns, positions[1], { 0, 0 }, { limit = 1 })
  876. eq(1, #rv)
  877. rv = get_extmarks(ns2, positions[1], { 0, 0 }, { limit = 1 })
  878. eq(1, #rv)
  879. -- get_next (no limit)
  880. rv = get_extmarks(ns, positions[1], positions[2])
  881. eq(2, #rv)
  882. rv = get_extmarks(ns2, positions[1], positions[2])
  883. eq(2, #rv)
  884. -- get_prev (no limit)
  885. rv = get_extmarks(ns, positions[2], positions[1])
  886. eq(2, #rv)
  887. rv = get_extmarks(ns2, positions[2], positions[1])
  888. eq(2, #rv)
  889. api.nvim_buf_del_extmark(0, ns, marks[1])
  890. rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
  891. eq(2, #rv)
  892. api.nvim_buf_del_extmark(0, ns2, marks[1])
  893. rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 })
  894. eq(2, #rv)
  895. end)
  896. it('mark set can create unique identifiers', function()
  897. -- create mark with id 1
  898. eq(1, set_extmark(ns, 1, positions[1][1], positions[1][2]))
  899. -- ask for unique id, it should be the next one, i e 2
  900. eq(2, set_extmark(ns, 0, positions[1][1], positions[1][2]))
  901. eq(3, set_extmark(ns, 3, positions[2][1], positions[2][2]))
  902. eq(4, set_extmark(ns, 0, positions[1][1], positions[1][2]))
  903. -- mixing manual and allocated id:s are not recommended, but it should
  904. -- do something reasonable
  905. eq(6, set_extmark(ns, 6, positions[2][1], positions[2][2]))
  906. eq(7, set_extmark(ns, 0, positions[1][1], positions[1][2]))
  907. eq(8, set_extmark(ns, 0, positions[1][1], positions[1][2]))
  908. end)
  909. it('auto indenting with enter works', function()
  910. -- op_reindent in ops.c
  911. feed(':set cindent<cr><esc>')
  912. feed(':set autoindent<cr><esc>')
  913. feed(':set shiftwidth=2<cr><esc>')
  914. feed('0iint <esc>A {1M1<esc>b<esc>')
  915. -- Set the mark on the M, should move..
  916. set_extmark(ns, marks[1], 0, 12)
  917. -- Set the mark before the cursor, should stay there
  918. set_extmark(ns, marks[2], 0, 10)
  919. feed('i<cr><esc>')
  920. local rv = get_extmark_by_id(ns, marks[1])
  921. eq({ 1, 3 }, rv)
  922. rv = get_extmark_by_id(ns, marks[2])
  923. eq({ 0, 10 }, rv)
  924. check_undo_redo(ns, marks[1], 0, 12, 1, 3)
  925. end)
  926. it('auto indenting entire line works', function()
  927. feed(':set cindent<cr><esc>')
  928. feed(':set autoindent<cr><esc>')
  929. feed(':set shiftwidth=2<cr><esc>')
  930. -- <c-f> will force an indent of 2
  931. feed('0iint <esc>A {<cr><esc>0i1M1<esc>')
  932. set_extmark(ns, marks[1], 1, 1)
  933. feed('0i<c-f><esc>')
  934. local rv = get_extmark_by_id(ns, marks[1])
  935. eq({ 1, 3 }, rv)
  936. check_undo_redo(ns, marks[1], 1, 1, 1, 3)
  937. -- now check when cursor at eol
  938. feed('uA<c-f><esc>')
  939. rv = get_extmark_by_id(ns, marks[1])
  940. eq({ 1, 3 }, rv)
  941. end)
  942. it('removing auto indenting with <C-D> works', function()
  943. feed(':set cindent<cr><esc>')
  944. feed(':set autoindent<cr><esc>')
  945. feed(':set shiftwidth=2<cr><esc>')
  946. feed('0i<tab><esc>')
  947. set_extmark(ns, marks[1], 0, 3)
  948. feed('bi<c-d><esc>')
  949. local rv = get_extmark_by_id(ns, marks[1])
  950. eq({ 0, 1 }, rv)
  951. check_undo_redo(ns, marks[1], 0, 3, 0, 1)
  952. -- check when cursor at eol
  953. feed('uA<c-d><esc>')
  954. rv = get_extmark_by_id(ns, marks[1])
  955. eq({ 0, 1 }, rv)
  956. end)
  957. it('indenting multiple lines with = works', function()
  958. feed(':set cindent<cr><esc>')
  959. feed(':set autoindent<cr><esc>')
  960. feed(':set shiftwidth=2<cr><esc>')
  961. feed('0iint <esc>A {<cr><bs>1M1<cr><bs>2M2<esc>')
  962. set_extmark(ns, marks[1], 1, 1)
  963. set_extmark(ns, marks[2], 2, 1)
  964. feed('=gg')
  965. check_undo_redo(ns, marks[1], 1, 1, 1, 3)
  966. check_undo_redo(ns, marks[2], 2, 1, 2, 5)
  967. end)
  968. it('substitutes by deleting inside the replace matches', function()
  969. -- do_sub in ex_cmds.c
  970. set_extmark(ns, marks[1], 0, 2)
  971. set_extmark(ns, marks[2], 0, 3)
  972. feed(':s/34/xx<cr>')
  973. check_undo_redo(ns, marks[1], 0, 2, 0, 4)
  974. check_undo_redo(ns, marks[2], 0, 3, 0, 4)
  975. end)
  976. it('substitutes when insert text > deleted', function()
  977. -- do_sub in ex_cmds.c
  978. set_extmark(ns, marks[1], 0, 2)
  979. set_extmark(ns, marks[2], 0, 3)
  980. feed(':s/34/xxx<cr>')
  981. check_undo_redo(ns, marks[1], 0, 2, 0, 5)
  982. check_undo_redo(ns, marks[2], 0, 3, 0, 5)
  983. end)
  984. it('substitutes when marks around eol', function()
  985. -- do_sub in ex_cmds.c
  986. set_extmark(ns, marks[1], 0, 4)
  987. set_extmark(ns, marks[2], 0, 5)
  988. feed(':s/5/xxx<cr>')
  989. check_undo_redo(ns, marks[1], 0, 4, 0, 7)
  990. check_undo_redo(ns, marks[2], 0, 5, 0, 7)
  991. end)
  992. it('substitutes over range insert text > deleted', function()
  993. -- do_sub in ex_cmds.c
  994. feed('A<cr>x34xx<esc>')
  995. feed('A<cr>xxx34<esc>')
  996. set_extmark(ns, marks[1], 0, 2)
  997. set_extmark(ns, marks[2], 1, 1)
  998. set_extmark(ns, marks[3], 2, 4)
  999. feed(':1,3s/34/xxx<cr><esc>')
  1000. check_undo_redo(ns, marks[1], 0, 2, 0, 5)
  1001. check_undo_redo(ns, marks[2], 1, 1, 1, 4)
  1002. check_undo_redo(ns, marks[3], 2, 4, 2, 6)
  1003. end)
  1004. it('substitutes multiple matches in a line', function()
  1005. -- do_sub in ex_cmds.c
  1006. feed('ddi3x3x3<esc>')
  1007. set_extmark(ns, marks[1], 0, 0)
  1008. set_extmark(ns, marks[2], 0, 2)
  1009. set_extmark(ns, marks[3], 0, 4)
  1010. feed(':s/3/yy/g<cr><esc>')
  1011. check_undo_redo(ns, marks[1], 0, 0, 0, 2)
  1012. check_undo_redo(ns, marks[2], 0, 2, 0, 5)
  1013. check_undo_redo(ns, marks[3], 0, 4, 0, 8)
  1014. end)
  1015. it('substitutes over multiple lines with newline in pattern', function()
  1016. feed('A<cr>67890<cr>xx<esc>')
  1017. set_extmark(ns, marks[1], 0, 3)
  1018. set_extmark(ns, marks[2], 0, 4)
  1019. set_extmark(ns, marks[3], 1, 0)
  1020. set_extmark(ns, marks[4], 1, 5)
  1021. set_extmark(ns, marks[5], 2, 0)
  1022. feed([[:1,2s:5\n:5 <cr>]])
  1023. check_undo_redo(ns, marks[1], 0, 3, 0, 3)
  1024. check_undo_redo(ns, marks[2], 0, 4, 0, 6)
  1025. check_undo_redo(ns, marks[3], 1, 0, 0, 6)
  1026. check_undo_redo(ns, marks[4], 1, 5, 0, 11)
  1027. check_undo_redo(ns, marks[5], 2, 0, 1, 0)
  1028. end)
  1029. it('inserting', function()
  1030. feed('A<cr>67890<cr>xx<esc>')
  1031. set_extmark(ns, marks[1], 0, 3)
  1032. set_extmark(ns, marks[2], 0, 4)
  1033. set_extmark(ns, marks[3], 1, 0)
  1034. set_extmark(ns, marks[4], 1, 5)
  1035. set_extmark(ns, marks[5], 2, 0)
  1036. set_extmark(ns, marks[6], 1, 2)
  1037. feed([[:1,2s:5\n67:X<cr>]])
  1038. check_undo_redo(ns, marks[1], 0, 3, 0, 3)
  1039. check_undo_redo(ns, marks[2], 0, 4, 0, 5)
  1040. check_undo_redo(ns, marks[3], 1, 0, 0, 5)
  1041. check_undo_redo(ns, marks[4], 1, 5, 0, 8)
  1042. check_undo_redo(ns, marks[5], 2, 0, 1, 0)
  1043. check_undo_redo(ns, marks[6], 1, 2, 0, 5)
  1044. end)
  1045. it('substitutes with multiple newlines in pattern', function()
  1046. feed('A<cr>67890<cr>xx<esc>')
  1047. set_extmark(ns, marks[1], 0, 4)
  1048. set_extmark(ns, marks[2], 0, 5)
  1049. set_extmark(ns, marks[3], 1, 0)
  1050. set_extmark(ns, marks[4], 1, 5)
  1051. set_extmark(ns, marks[5], 2, 0)
  1052. feed([[:1,2s:\n.*\n:X<cr>]])
  1053. check_undo_redo(ns, marks[1], 0, 4, 0, 4)
  1054. check_undo_redo(ns, marks[2], 0, 5, 0, 6)
  1055. check_undo_redo(ns, marks[3], 1, 0, 0, 6)
  1056. check_undo_redo(ns, marks[4], 1, 5, 0, 6)
  1057. check_undo_redo(ns, marks[5], 2, 0, 0, 6)
  1058. end)
  1059. it('substitutes over multiple lines with replace in substitution', function()
  1060. feed('A<cr>67890<cr>xx<esc>')
  1061. set_extmark(ns, marks[1], 0, 1)
  1062. set_extmark(ns, marks[2], 0, 2)
  1063. set_extmark(ns, marks[3], 0, 4)
  1064. set_extmark(ns, marks[4], 1, 0)
  1065. set_extmark(ns, marks[5], 2, 0)
  1066. feed([[:1,2s:3:\r<cr>]])
  1067. check_undo_redo(ns, marks[1], 0, 1, 0, 1)
  1068. check_undo_redo(ns, marks[2], 0, 2, 1, 0)
  1069. check_undo_redo(ns, marks[3], 0, 4, 1, 1)
  1070. check_undo_redo(ns, marks[4], 1, 0, 2, 0)
  1071. check_undo_redo(ns, marks[5], 2, 0, 3, 0)
  1072. feed('u')
  1073. feed([[:1,2s:3:\rxx<cr>]])
  1074. eq({ 1, 3 }, get_extmark_by_id(ns, marks[3]))
  1075. end)
  1076. it('substitutes over multiple lines with replace in substitution', function()
  1077. feed('A<cr>x3<cr>xx<esc>')
  1078. set_extmark(ns, marks[1], 1, 0)
  1079. set_extmark(ns, marks[2], 1, 1)
  1080. set_extmark(ns, marks[3], 1, 2)
  1081. feed([[:2,2s:3:\r<cr>]])
  1082. check_undo_redo(ns, marks[1], 1, 0, 1, 0)
  1083. check_undo_redo(ns, marks[2], 1, 1, 2, 0)
  1084. check_undo_redo(ns, marks[3], 1, 2, 2, 0)
  1085. end)
  1086. it('substitutes over multiple lines with replace in substitution', function()
  1087. feed('A<cr>x3<cr>xx<esc>')
  1088. set_extmark(ns, marks[1], 0, 1)
  1089. set_extmark(ns, marks[2], 0, 2)
  1090. set_extmark(ns, marks[3], 0, 4)
  1091. set_extmark(ns, marks[4], 1, 1)
  1092. set_extmark(ns, marks[5], 2, 0)
  1093. feed([[:1,2s:3:\r<cr>]])
  1094. check_undo_redo(ns, marks[1], 0, 1, 0, 1)
  1095. check_undo_redo(ns, marks[2], 0, 2, 1, 0)
  1096. check_undo_redo(ns, marks[3], 0, 4, 1, 1)
  1097. check_undo_redo(ns, marks[4], 1, 1, 3, 0)
  1098. check_undo_redo(ns, marks[5], 2, 0, 4, 0)
  1099. feed('u')
  1100. feed([[:1,2s:3:\rxx<cr>]])
  1101. check_undo_redo(ns, marks[3], 0, 4, 1, 3)
  1102. end)
  1103. it('substitutes with newline in match and sub, delta is 0', function()
  1104. feed('A<cr>67890<cr>xx<esc>')
  1105. set_extmark(ns, marks[1], 0, 3)
  1106. set_extmark(ns, marks[2], 0, 4)
  1107. set_extmark(ns, marks[3], 0, 5)
  1108. set_extmark(ns, marks[4], 1, 0)
  1109. set_extmark(ns, marks[5], 1, 5)
  1110. set_extmark(ns, marks[6], 2, 0)
  1111. feed([[:1,1s:5\n:\r<cr>]])
  1112. check_undo_redo(ns, marks[1], 0, 3, 0, 3)
  1113. check_undo_redo(ns, marks[2], 0, 4, 1, 0)
  1114. check_undo_redo(ns, marks[3], 0, 5, 1, 0)
  1115. check_undo_redo(ns, marks[4], 1, 0, 1, 0)
  1116. check_undo_redo(ns, marks[5], 1, 5, 1, 5)
  1117. check_undo_redo(ns, marks[6], 2, 0, 2, 0)
  1118. end)
  1119. it('substitutes with newline in match and sub, delta > 0', function()
  1120. feed('A<cr>67890<cr>xx<esc>')
  1121. set_extmark(ns, marks[1], 0, 3)
  1122. set_extmark(ns, marks[2], 0, 4)
  1123. set_extmark(ns, marks[3], 0, 5)
  1124. set_extmark(ns, marks[4], 1, 0)
  1125. set_extmark(ns, marks[5], 1, 5)
  1126. set_extmark(ns, marks[6], 2, 0)
  1127. feed([[:1,1s:5\n:\r\r<cr>]])
  1128. check_undo_redo(ns, marks[1], 0, 3, 0, 3)
  1129. check_undo_redo(ns, marks[2], 0, 4, 2, 0)
  1130. check_undo_redo(ns, marks[3], 0, 5, 2, 0)
  1131. check_undo_redo(ns, marks[4], 1, 0, 2, 0)
  1132. check_undo_redo(ns, marks[5], 1, 5, 2, 5)
  1133. check_undo_redo(ns, marks[6], 2, 0, 3, 0)
  1134. end)
  1135. it('substitutes with newline in match and sub, delta < 0', function()
  1136. feed('A<cr>67890<cr>xx<cr>xx<esc>')
  1137. set_extmark(ns, marks[1], 0, 3)
  1138. set_extmark(ns, marks[2], 0, 4)
  1139. set_extmark(ns, marks[3], 0, 5)
  1140. set_extmark(ns, marks[4], 1, 0)
  1141. set_extmark(ns, marks[5], 1, 5)
  1142. set_extmark(ns, marks[6], 2, 1)
  1143. set_extmark(ns, marks[7], 3, 0)
  1144. feed([[:1,2s:5\n.*\n:\r<cr>]])
  1145. check_undo_redo(ns, marks[1], 0, 3, 0, 3)
  1146. check_undo_redo(ns, marks[2], 0, 4, 1, 0)
  1147. check_undo_redo(ns, marks[3], 0, 5, 1, 0)
  1148. check_undo_redo(ns, marks[4], 1, 0, 1, 0)
  1149. check_undo_redo(ns, marks[5], 1, 5, 1, 0)
  1150. check_undo_redo(ns, marks[6], 2, 1, 1, 1)
  1151. check_undo_redo(ns, marks[7], 3, 0, 2, 0)
  1152. end)
  1153. it('substitutes with backrefs, newline inserted into sub', function()
  1154. feed('A<cr>67890<cr>xx<cr>xx<esc>')
  1155. set_extmark(ns, marks[1], 0, 3)
  1156. set_extmark(ns, marks[2], 0, 4)
  1157. set_extmark(ns, marks[3], 0, 5)
  1158. set_extmark(ns, marks[4], 1, 0)
  1159. set_extmark(ns, marks[5], 1, 5)
  1160. set_extmark(ns, marks[6], 2, 0)
  1161. feed([[:1,1s:5\(\n\):\0\1<cr>]])
  1162. check_undo_redo(ns, marks[1], 0, 3, 0, 3)
  1163. check_undo_redo(ns, marks[2], 0, 4, 2, 0)
  1164. check_undo_redo(ns, marks[3], 0, 5, 2, 0)
  1165. check_undo_redo(ns, marks[4], 1, 0, 2, 0)
  1166. check_undo_redo(ns, marks[5], 1, 5, 2, 5)
  1167. check_undo_redo(ns, marks[6], 2, 0, 3, 0)
  1168. end)
  1169. it('substitutes a ^', function()
  1170. set_extmark(ns, marks[1], 0, 0)
  1171. set_extmark(ns, marks[2], 0, 1)
  1172. feed([[:s:^:x<cr>]])
  1173. check_undo_redo(ns, marks[1], 0, 0, 0, 1)
  1174. check_undo_redo(ns, marks[2], 0, 1, 0, 2)
  1175. end)
  1176. it('using <c-a> without increase in order of magnitude', function()
  1177. -- do_addsub in ops.c
  1178. feed('ddiabc998xxx<esc>Tc')
  1179. set_extmark(ns, marks[1], 0, 2)
  1180. set_extmark(ns, marks[2], 0, 3)
  1181. set_extmark(ns, marks[3], 0, 5)
  1182. set_extmark(ns, marks[4], 0, 6)
  1183. set_extmark(ns, marks[5], 0, 7)
  1184. feed('<c-a>')
  1185. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  1186. check_undo_redo(ns, marks[2], 0, 3, 0, 6)
  1187. check_undo_redo(ns, marks[3], 0, 5, 0, 6)
  1188. check_undo_redo(ns, marks[4], 0, 6, 0, 6)
  1189. check_undo_redo(ns, marks[5], 0, 7, 0, 7)
  1190. end)
  1191. it('using <c-a> when increase in order of magnitude', function()
  1192. -- do_addsub in ops.c
  1193. feed('ddiabc999xxx<esc>Tc')
  1194. set_extmark(ns, marks[1], 0, 2)
  1195. set_extmark(ns, marks[2], 0, 3)
  1196. set_extmark(ns, marks[3], 0, 5)
  1197. set_extmark(ns, marks[4], 0, 6)
  1198. set_extmark(ns, marks[5], 0, 7)
  1199. feed('<c-a>')
  1200. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  1201. check_undo_redo(ns, marks[2], 0, 3, 0, 7)
  1202. check_undo_redo(ns, marks[3], 0, 5, 0, 7)
  1203. check_undo_redo(ns, marks[4], 0, 6, 0, 7)
  1204. check_undo_redo(ns, marks[5], 0, 7, 0, 8)
  1205. end)
  1206. it('using <c-a> when negative and without decrease in order of magnitude', function()
  1207. feed('ddiabc-999xxx<esc>T-')
  1208. set_extmark(ns, marks[1], 0, 2)
  1209. set_extmark(ns, marks[2], 0, 3)
  1210. set_extmark(ns, marks[3], 0, 6)
  1211. set_extmark(ns, marks[4], 0, 7)
  1212. set_extmark(ns, marks[5], 0, 8)
  1213. feed('<c-a>')
  1214. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  1215. check_undo_redo(ns, marks[2], 0, 3, 0, 7)
  1216. check_undo_redo(ns, marks[3], 0, 6, 0, 7)
  1217. check_undo_redo(ns, marks[4], 0, 7, 0, 7)
  1218. check_undo_redo(ns, marks[5], 0, 8, 0, 8)
  1219. end)
  1220. it('using <c-a> when negative and decrease in order of magnitude', function()
  1221. feed('ddiabc-1000xxx<esc>T-')
  1222. set_extmark(ns, marks[1], 0, 2)
  1223. set_extmark(ns, marks[2], 0, 3)
  1224. set_extmark(ns, marks[3], 0, 7)
  1225. set_extmark(ns, marks[4], 0, 8)
  1226. set_extmark(ns, marks[5], 0, 9)
  1227. feed('<c-a>')
  1228. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  1229. check_undo_redo(ns, marks[2], 0, 3, 0, 7)
  1230. check_undo_redo(ns, marks[3], 0, 7, 0, 7)
  1231. check_undo_redo(ns, marks[4], 0, 8, 0, 7)
  1232. check_undo_redo(ns, marks[5], 0, 9, 0, 8)
  1233. end)
  1234. it('using <c-x> without decrease in order of magnitude', function()
  1235. -- do_addsub in ops.c
  1236. feed('ddiabc999xxx<esc>Tc')
  1237. set_extmark(ns, marks[1], 0, 2)
  1238. set_extmark(ns, marks[2], 0, 3)
  1239. set_extmark(ns, marks[3], 0, 5)
  1240. set_extmark(ns, marks[4], 0, 6)
  1241. set_extmark(ns, marks[5], 0, 7)
  1242. feed('<c-x>')
  1243. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  1244. check_undo_redo(ns, marks[2], 0, 3, 0, 6)
  1245. check_undo_redo(ns, marks[3], 0, 5, 0, 6)
  1246. check_undo_redo(ns, marks[4], 0, 6, 0, 6)
  1247. check_undo_redo(ns, marks[5], 0, 7, 0, 7)
  1248. end)
  1249. it('using <c-x> when decrease in order of magnitude', function()
  1250. -- do_addsub in ops.c
  1251. feed('ddiabc1000xxx<esc>Tc')
  1252. set_extmark(ns, marks[1], 0, 2)
  1253. set_extmark(ns, marks[2], 0, 3)
  1254. set_extmark(ns, marks[3], 0, 6)
  1255. set_extmark(ns, marks[4], 0, 7)
  1256. set_extmark(ns, marks[5], 0, 8)
  1257. feed('<c-x>')
  1258. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  1259. check_undo_redo(ns, marks[2], 0, 3, 0, 6)
  1260. check_undo_redo(ns, marks[3], 0, 6, 0, 6)
  1261. check_undo_redo(ns, marks[4], 0, 7, 0, 6)
  1262. check_undo_redo(ns, marks[5], 0, 8, 0, 7)
  1263. end)
  1264. it('using <c-x> when negative and without increase in order of magnitude', function()
  1265. feed('ddiabc-998xxx<esc>T-')
  1266. set_extmark(ns, marks[1], 0, 2)
  1267. set_extmark(ns, marks[2], 0, 3)
  1268. set_extmark(ns, marks[3], 0, 6)
  1269. set_extmark(ns, marks[4], 0, 7)
  1270. set_extmark(ns, marks[5], 0, 8)
  1271. feed('<c-x>')
  1272. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  1273. check_undo_redo(ns, marks[2], 0, 3, 0, 7)
  1274. check_undo_redo(ns, marks[3], 0, 6, 0, 7)
  1275. check_undo_redo(ns, marks[4], 0, 7, 0, 7)
  1276. check_undo_redo(ns, marks[5], 0, 8, 0, 8)
  1277. end)
  1278. it('using <c-x> when negative and increase in order of magnitude', function()
  1279. feed('ddiabc-999xxx<esc>T-')
  1280. set_extmark(ns, marks[1], 0, 2)
  1281. set_extmark(ns, marks[2], 0, 3)
  1282. set_extmark(ns, marks[3], 0, 6)
  1283. set_extmark(ns, marks[4], 0, 7)
  1284. set_extmark(ns, marks[5], 0, 8)
  1285. feed('<c-x>')
  1286. check_undo_redo(ns, marks[1], 0, 2, 0, 2)
  1287. check_undo_redo(ns, marks[2], 0, 3, 0, 8)
  1288. check_undo_redo(ns, marks[3], 0, 6, 0, 8)
  1289. check_undo_redo(ns, marks[4], 0, 7, 0, 8)
  1290. check_undo_redo(ns, marks[5], 0, 8, 0, 9)
  1291. end)
  1292. it('throws consistent error codes', function()
  1293. local ns_invalid = ns2 + 1
  1294. eq(
  1295. "Invalid 'ns_id': 3",
  1296. pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2])
  1297. )
  1298. eq("Invalid 'ns_id': 3", pcall_err(api.nvim_buf_del_extmark, 0, ns_invalid, marks[1]))
  1299. eq("Invalid 'ns_id': 3", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
  1300. eq("Invalid 'ns_id': 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
  1301. end)
  1302. it('when col = line-length, set the mark on eol', function()
  1303. set_extmark(ns, marks[1], 0, -1)
  1304. local rv = get_extmark_by_id(ns, marks[1])
  1305. eq({ 0, init_text:len() }, rv)
  1306. -- Test another
  1307. set_extmark(ns, marks[1], 0, -1)
  1308. rv = get_extmark_by_id(ns, marks[1])
  1309. eq({ 0, init_text:len() }, rv)
  1310. end)
  1311. it('when col = line-length, set the mark on eol', function()
  1312. local invalid_col = init_text:len() + 1
  1313. eq("Invalid 'col': out of range", pcall_err(set_extmark, ns, marks[1], 0, invalid_col))
  1314. end)
  1315. it('fails when line > line_count', function()
  1316. local invalid_col = init_text:len() + 1
  1317. local invalid_lnum = 3
  1318. eq(
  1319. "Invalid 'line': out of range",
  1320. pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col)
  1321. )
  1322. eq({}, get_extmark_by_id(ns, marks[1]))
  1323. end)
  1324. it('bug from check_col in extmark_set', function()
  1325. -- This bug was caused by extmark_set always using check_col. check_col
  1326. -- always uses the current buffer. This wasn't working during undo so we
  1327. -- now use check_col and check_lnum only when they are required.
  1328. feed('A<cr>67890<cr>xx<esc>')
  1329. feed('A<cr>12345<cr>67890<cr>xx<esc>')
  1330. set_extmark(ns, marks[1], 3, 4)
  1331. feed([[:1,5s:5\n:5 <cr>]])
  1332. check_undo_redo(ns, marks[1], 3, 4, 2, 6)
  1333. end)
  1334. it('in read-only buffer', function()
  1335. command('view! runtime/doc/help.txt')
  1336. eq(true, api.nvim_get_option_value('ro', {}))
  1337. local id = set_extmark(ns, 0, 0, 2)
  1338. eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1))
  1339. end)
  1340. it('can set a mark to other buffer', function()
  1341. local buf = request('nvim_create_buf', 0, 1)
  1342. request('nvim_buf_set_lines', buf, 0, -1, 1, { '', '' })
  1343. local id = api.nvim_buf_set_extmark(buf, ns, 1, 0, {})
  1344. eq({ { id, 1, 0 } }, api.nvim_buf_get_extmarks(buf, ns, 0, -1, {}))
  1345. end)
  1346. it('does not crash with append/delete/undo sequence', function()
  1347. exec([[
  1348. let ns = nvim_create_namespace('myplugin')
  1349. call nvim_buf_set_extmark(0, ns, 0, 0, {})
  1350. call append(0, '')
  1351. %delete
  1352. undo]])
  1353. assert_alive()
  1354. end)
  1355. it('works with left and right gravity', function()
  1356. -- right gravity should move with inserted text, while
  1357. -- left gravity should stay in place.
  1358. api.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = false })
  1359. api.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = true })
  1360. feed([[Aasdfasdf]])
  1361. eq({ { 1, 0, 5 }, { 2, 0, 13 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
  1362. -- but both move when text is inserted before
  1363. feed([[<esc>Iasdf<esc>]])
  1364. -- eq({}, api.nvim_buf_get_lines(0, 0, -1, true))
  1365. eq({ { 1, 0, 9 }, { 2, 0, 17 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
  1366. -- clear text
  1367. api.nvim_buf_set_text(0, 0, 0, 0, 17, {})
  1368. -- handles set_text correctly as well
  1369. eq({ { 1, 0, 0 }, { 2, 0, 0 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
  1370. api.nvim_buf_set_text(0, 0, 0, 0, 0, { 'asdfasdf' })
  1371. eq({ { 1, 0, 0 }, { 2, 0, 8 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
  1372. feed('u')
  1373. -- handles pasting
  1374. exec([[let @a='asdfasdf']])
  1375. feed([["ap]])
  1376. eq({ { 1, 0, 0 }, { 2, 0, 8 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
  1377. end)
  1378. it('can accept "end_row" or "end_line" #16548', function()
  1379. set_extmark(ns, marks[1], 0, 0, {
  1380. end_col = 0,
  1381. end_line = 1,
  1382. })
  1383. eq({
  1384. {
  1385. 1,
  1386. 0,
  1387. 0,
  1388. {
  1389. ns_id = 1,
  1390. end_col = 0,
  1391. end_row = 1,
  1392. right_gravity = true,
  1393. end_right_gravity = false,
  1394. },
  1395. },
  1396. }, get_extmarks(ns, 0, -1, { details = true }))
  1397. end)
  1398. it('in prompt buffer', function()
  1399. feed('dd')
  1400. local id = set_extmark(ns, marks[1], 0, 0, {})
  1401. api.nvim_set_option_value('buftype', 'prompt', {})
  1402. feed('i<esc>')
  1403. eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1))
  1404. end)
  1405. it('can get details', function()
  1406. set_extmark(ns, marks[1], 0, 0, {
  1407. conceal = 'c',
  1408. cursorline_hl_group = 'Statement',
  1409. end_col = 0,
  1410. end_right_gravity = true,
  1411. end_row = 1,
  1412. hl_eol = true,
  1413. hl_group = 'String',
  1414. hl_mode = 'blend',
  1415. line_hl_group = 'Statement',
  1416. number_hl_group = 'Statement',
  1417. priority = 0,
  1418. right_gravity = false,
  1419. sign_hl_group = 'Statement',
  1420. sign_text = '>>',
  1421. spell = true,
  1422. virt_lines = {
  1423. { { 'lines', 'Macro' }, { '???' }, { ';;;', '' } },
  1424. { { 'stack', { 'Type', 'Search' } }, { '!!!' } },
  1425. },
  1426. virt_lines_above = true,
  1427. virt_lines_leftcol = true,
  1428. virt_text = { { 'text', 'Macro' }, { '???' }, { 'stack', { 'Type', 'Search' } } },
  1429. virt_text_hide = true,
  1430. virt_text_pos = 'right_align',
  1431. })
  1432. set_extmark(ns, marks[2], 0, 0, {
  1433. priority = 0,
  1434. virt_text = { { '', 'Macro' }, { '', { 'Type', 'Search' } }, { '' } },
  1435. virt_text_win_col = 1,
  1436. })
  1437. eq({
  1438. 0,
  1439. 0,
  1440. {
  1441. conceal = 'c',
  1442. cursorline_hl_group = 'Statement',
  1443. end_col = 0,
  1444. end_right_gravity = true,
  1445. end_row = 1,
  1446. hl_eol = true,
  1447. hl_group = 'String',
  1448. hl_mode = 'blend',
  1449. line_hl_group = 'Statement',
  1450. ns_id = 1,
  1451. number_hl_group = 'Statement',
  1452. priority = 0,
  1453. right_gravity = false,
  1454. sign_hl_group = 'Statement',
  1455. sign_text = '>>',
  1456. spell = true,
  1457. virt_lines = {
  1458. { { 'lines', 'Macro' }, { '???' }, { ';;;', '' } },
  1459. { { 'stack', { 'Type', 'Search' } }, { '!!!' } },
  1460. },
  1461. virt_lines_above = true,
  1462. virt_lines_leftcol = true,
  1463. virt_text = { { 'text', 'Macro' }, { '???' }, { 'stack', { 'Type', 'Search' } } },
  1464. virt_text_repeat_linebreak = false,
  1465. virt_text_hide = true,
  1466. virt_text_pos = 'right_align',
  1467. },
  1468. }, get_extmark_by_id(ns, marks[1], { details = true }))
  1469. eq({
  1470. 0,
  1471. 0,
  1472. {
  1473. ns_id = 1,
  1474. right_gravity = true,
  1475. priority = 0,
  1476. virt_text = { { '', 'Macro' }, { '', { 'Type', 'Search' } }, { '' } },
  1477. virt_text_repeat_linebreak = false,
  1478. virt_text_hide = false,
  1479. virt_text_pos = 'win_col',
  1480. virt_text_win_col = 1,
  1481. },
  1482. }, get_extmark_by_id(ns, marks[2], { details = true }))
  1483. set_extmark(ns, marks[3], 0, 0, { cursorline_hl_group = 'Statement' })
  1484. eq({
  1485. 0,
  1486. 0,
  1487. {
  1488. ns_id = 1,
  1489. cursorline_hl_group = 'Statement',
  1490. priority = 4096,
  1491. right_gravity = true,
  1492. },
  1493. }, get_extmark_by_id(ns, marks[3], { details = true }))
  1494. set_extmark(ns, marks[4], 0, 0, {
  1495. end_col = 1,
  1496. conceal = 'a',
  1497. spell = true,
  1498. })
  1499. eq({
  1500. 0,
  1501. 0,
  1502. {
  1503. conceal = 'a',
  1504. end_col = 1,
  1505. end_right_gravity = false,
  1506. end_row = 0,
  1507. ns_id = 1,
  1508. right_gravity = true,
  1509. spell = true,
  1510. },
  1511. }, get_extmark_by_id(ns, marks[4], { details = true }))
  1512. set_extmark(ns, marks[5], 0, 0, {
  1513. end_col = 1,
  1514. spell = false,
  1515. })
  1516. eq({
  1517. 0,
  1518. 0,
  1519. {
  1520. end_col = 1,
  1521. end_right_gravity = false,
  1522. end_row = 0,
  1523. ns_id = 1,
  1524. right_gravity = true,
  1525. spell = false,
  1526. },
  1527. }, get_extmark_by_id(ns, marks[5], { details = true }))
  1528. api.nvim_buf_clear_namespace(0, ns, 0, -1)
  1529. -- legacy sign mark includes sign name
  1530. command('sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine')
  1531. command('sign place 1 name=sign1 line=1')
  1532. eq({
  1533. {
  1534. 1,
  1535. 0,
  1536. 0,
  1537. {
  1538. cursorline_hl_group = 'CursorLine',
  1539. invalidate = true,
  1540. line_hl_group = 'LineNr',
  1541. ns_id = 0,
  1542. number_hl_group = 'Normal',
  1543. priority = 10,
  1544. right_gravity = true,
  1545. sign_hl_group = 'Title',
  1546. sign_name = 'sign1',
  1547. sign_text = 's1',
  1548. undo_restore = false,
  1549. },
  1550. },
  1551. }, get_extmarks(-1, 0, -1, { details = true }))
  1552. end)
  1553. it('can get marks from anonymous namespaces', function()
  1554. ns = request('nvim_create_namespace', '')
  1555. ns2 = request('nvim_create_namespace', '')
  1556. set_extmark(ns, 1, 0, 0, {})
  1557. set_extmark(ns2, 2, 1, 0, {})
  1558. eq({
  1559. { 1, 0, 0, { ns_id = ns, right_gravity = true } },
  1560. { 2, 1, 0, { ns_id = ns2, right_gravity = true } },
  1561. }, get_extmarks(-1, 0, -1, { details = true }))
  1562. end)
  1563. it('can filter by extmark properties', function()
  1564. set_extmark(ns, 1, 0, 0, {})
  1565. set_extmark(ns, 2, 0, 0, { hl_group = 'Normal' })
  1566. set_extmark(ns, 3, 0, 0, { sign_text = '>>' })
  1567. set_extmark(ns, 4, 0, 0, { virt_text = { { 'text', 'Normal' } } })
  1568. set_extmark(ns, 5, 0, 0, { virt_lines = { { { 'line', 'Normal' } } } })
  1569. eq(5, #get_extmarks(-1, 0, -1, {}))
  1570. eq({ { 2, 0, 0 } }, get_extmarks(-1, 0, -1, { type = 'highlight' }))
  1571. eq({ { 3, 0, 0 } }, get_extmarks(-1, 0, -1, { type = 'sign' }))
  1572. eq({ { 4, 0, 0 } }, get_extmarks(-1, 0, -1, { type = 'virt_text' }))
  1573. eq({ { 5, 0, 0 } }, get_extmarks(-1, 0, -1, { type = 'virt_lines' }))
  1574. end)
  1575. it('invalidated marks are deleted', function()
  1576. screen = Screen.new(40, 6)
  1577. feed('dd6iaaa bbb ccc<CR><ESC>gg')
  1578. api.nvim_set_option_value('signcolumn', 'auto:2', {})
  1579. set_extmark(ns, 1, 0, 0, { invalidate = true, sign_text = 'S1', end_row = 1 })
  1580. set_extmark(ns, 2, 1, 0, { invalidate = true, sign_text = 'S2', end_row = 2 })
  1581. -- mark with invalidate is removed
  1582. command('d2')
  1583. screen:expect([[
  1584. S2^aaa bbb ccc |
  1585. {7: }aaa bbb ccc |*3
  1586. {7: } |
  1587. |
  1588. ]])
  1589. -- mark is restored with undo_restore == true
  1590. command('silent undo')
  1591. screen:expect([[
  1592. S1{7: }^aaa bbb ccc |
  1593. S2S1aaa bbb ccc |
  1594. S2{7: }aaa bbb ccc |
  1595. {7: }aaa bbb ccc |*2
  1596. |
  1597. ]])
  1598. -- decor is not removed twice
  1599. command('d3')
  1600. api.nvim_buf_del_extmark(0, ns, 1)
  1601. command('silent undo')
  1602. -- mark is deleted with undo_restore == false
  1603. set_extmark(ns, 1, 0, 0, { invalidate = true, undo_restore = false, sign_text = 'S1' })
  1604. set_extmark(ns, 2, 1, 0, { invalidate = true, undo_restore = false, sign_text = 'S2' })
  1605. command('1d 2')
  1606. eq(0, #get_extmarks(-1, 0, -1, {}))
  1607. -- mark is not removed when deleting bytes before the range
  1608. set_extmark(ns, 3, 0, 4, {
  1609. invalidate = true,
  1610. undo_restore = true,
  1611. hl_group = 'Error',
  1612. end_col = 7,
  1613. right_gravity = false,
  1614. })
  1615. feed('dw')
  1616. eq(3, get_extmark_by_id(ns, 3, { details = true })[3].end_col)
  1617. -- mark is not removed when deleting bytes at the start of the range
  1618. feed('x')
  1619. eq(2, get_extmark_by_id(ns, 3, { details = true })[3].end_col)
  1620. -- mark is not removed when deleting bytes from the end of the range
  1621. feed('lx')
  1622. eq(1, get_extmark_by_id(ns, 3, { details = true })[3].end_col)
  1623. -- mark is not removed when deleting bytes beyond end of the range
  1624. feed('x')
  1625. eq(1, get_extmark_by_id(ns, 3, { details = true })[3].end_col)
  1626. -- mark is removed when all bytes in the range are deleted
  1627. feed('hx')
  1628. eq(true, get_extmark_by_id(ns, 3, { details = true })[3].invalid)
  1629. -- mark is restored with undo_restore == true if pos did not change
  1630. command('undo')
  1631. eq(nil, get_extmark_by_id(ns, 3, { details = true })[3].invalid)
  1632. -- multiline mark is not removed when start of its range is deleted
  1633. set_extmark(ns, 4, 1, 4, {
  1634. undo_restore = false,
  1635. invalidate = true,
  1636. hl_group = 'Error',
  1637. end_col = 7,
  1638. end_row = 3,
  1639. })
  1640. feed('ddDdd')
  1641. eq({ 0, 0 }, get_extmark_by_id(ns, 4, {}))
  1642. -- multiline mark is removed when entirety of its range is deleted
  1643. feed('vj2ed')
  1644. eq({}, get_extmark_by_id(ns, 4, {}))
  1645. end)
  1646. it('can set a URL', function()
  1647. local url1 = 'https://example.com'
  1648. local url2 = 'http://127.0.0.1'
  1649. set_extmark(ns, 1, 0, 0, { url = url1, end_col = 3 })
  1650. set_extmark(ns, 2, 0, 3, { url = url2, hl_group = 'Search', end_col = 5 })
  1651. local extmarks = get_extmarks(ns, 0, -1, { details = true })
  1652. eq(2, #extmarks)
  1653. eq(url1, extmarks[1][4].url)
  1654. eq(url2, extmarks[2][4].url)
  1655. eq('Search', extmarks[2][4].hl_group)
  1656. end)
  1657. it('respects priority', function()
  1658. screen = Screen.new(15, 10)
  1659. set_extmark(ns, marks[1], 0, 0, {
  1660. hl_group = 'Comment',
  1661. end_col = 2,
  1662. priority = 20,
  1663. })
  1664. -- Extmark defined after first extmark but has lower priority, first extmark "wins"
  1665. set_extmark(ns, marks[2], 0, 0, {
  1666. hl_group = 'String',
  1667. end_col = 2,
  1668. priority = 10,
  1669. })
  1670. screen:expect {
  1671. grid = [[
  1672. {1:12}34^5 |
  1673. {2:~ }|*8
  1674. |
  1675. ]],
  1676. attr_ids = {
  1677. [1] = { foreground = Screen.colors.Blue1 },
  1678. [2] = { foreground = Screen.colors.Blue1, bold = true },
  1679. },
  1680. }
  1681. end)
  1682. end)
  1683. describe('Extmarks buffer api with many marks', function()
  1684. local ns1
  1685. local ns2
  1686. local ns_marks = {}
  1687. before_each(function()
  1688. clear()
  1689. ns1 = request('nvim_create_namespace', 'ns1')
  1690. ns2 = request('nvim_create_namespace', 'ns2')
  1691. ns_marks = { [ns1] = {}, [ns2] = {} }
  1692. local lines = {}
  1693. for i = 1, 30 do
  1694. lines[#lines + 1] = string.rep('x ', i)
  1695. end
  1696. api.nvim_buf_set_lines(0, 0, -1, true, lines)
  1697. local ns = ns1
  1698. local q = 0
  1699. for i = 0, 29 do
  1700. for j = 0, i do
  1701. local id = set_extmark(ns, 0, i, j)
  1702. eq(nil, ns_marks[ns][id])
  1703. ok(id > 0)
  1704. ns_marks[ns][id] = { i, j }
  1705. ns = ns1 + ns2 - ns
  1706. q = q + 1
  1707. end
  1708. end
  1709. eq(233, #ns_marks[ns1])
  1710. eq(232, #ns_marks[ns2])
  1711. end)
  1712. local function get_marks(ns)
  1713. local mark_list = get_extmarks(ns, 0, -1)
  1714. local marks = {}
  1715. for _, mark in ipairs(mark_list) do
  1716. local id, row, col = unpack(mark)
  1717. eq(nil, marks[id], 'duplicate mark')
  1718. marks[id] = { row, col }
  1719. end
  1720. return marks
  1721. end
  1722. it('can get marks', function()
  1723. eq(ns_marks[ns1], get_marks(ns1))
  1724. eq(ns_marks[ns2], get_marks(ns2))
  1725. end)
  1726. it('can clear all marks in ns', function()
  1727. api.nvim_buf_clear_namespace(0, ns1, 0, -1)
  1728. eq({}, get_marks(ns1))
  1729. eq(ns_marks[ns2], get_marks(ns2))
  1730. api.nvim_buf_clear_namespace(0, ns2, 0, -1)
  1731. eq({}, get_marks(ns1))
  1732. eq({}, get_marks(ns2))
  1733. end)
  1734. it('can clear line range', function()
  1735. api.nvim_buf_clear_namespace(0, ns1, 10, 20)
  1736. for id, mark in pairs(ns_marks[ns1]) do
  1737. if 10 <= mark[1] and mark[1] < 20 then
  1738. ns_marks[ns1][id] = nil
  1739. end
  1740. end
  1741. eq(ns_marks[ns1], get_marks(ns1))
  1742. eq(ns_marks[ns2], get_marks(ns2))
  1743. api.nvim_buf_clear_namespace(0, ns1, 0, 10)
  1744. for id, mark in pairs(ns_marks[ns1]) do
  1745. if mark[1] < 10 then
  1746. ns_marks[ns1][id] = nil
  1747. end
  1748. end
  1749. eq(ns_marks[ns1], get_marks(ns1))
  1750. eq(ns_marks[ns2], get_marks(ns2))
  1751. api.nvim_buf_clear_namespace(0, ns1, 20, -1)
  1752. for id, mark in pairs(ns_marks[ns1]) do
  1753. if mark[1] >= 20 then
  1754. ns_marks[ns1][id] = nil
  1755. end
  1756. end
  1757. eq(ns_marks[ns1], get_marks(ns1))
  1758. eq(ns_marks[ns2], get_marks(ns2))
  1759. end)
  1760. it('can delete line', function()
  1761. feed('10Gdd')
  1762. for _, marks in pairs(ns_marks) do
  1763. for id, mark in pairs(marks) do
  1764. if mark[1] == 9 then
  1765. marks[id] = { 9, 0 }
  1766. elseif mark[1] >= 10 then
  1767. mark[1] = mark[1] - 1
  1768. end
  1769. end
  1770. end
  1771. eq(ns_marks[ns1], get_marks(ns1))
  1772. eq(ns_marks[ns2], get_marks(ns2))
  1773. end)
  1774. it('can delete lines', function()
  1775. feed('10G10dd')
  1776. for _, marks in pairs(ns_marks) do
  1777. for id, mark in pairs(marks) do
  1778. if 9 <= mark[1] and mark[1] < 19 then
  1779. marks[id] = { 9, 0 }
  1780. elseif mark[1] >= 19 then
  1781. mark[1] = mark[1] - 10
  1782. end
  1783. end
  1784. end
  1785. eq(ns_marks[ns1], get_marks(ns1))
  1786. eq(ns_marks[ns2], get_marks(ns2))
  1787. end)
  1788. it('can wipe buffer', function()
  1789. command('bwipe!')
  1790. eq({}, get_marks(ns1))
  1791. eq({}, get_marks(ns2))
  1792. end)
  1793. end)
  1794. describe('API/win_extmark', function()
  1795. local screen
  1796. local marks, line1, line2
  1797. local ns
  1798. before_each(function()
  1799. -- Initialize some namespaces and insert text into a buffer
  1800. marks = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
  1801. line1 = 'non ui-watched line'
  1802. line2 = 'ui-watched line'
  1803. clear()
  1804. insert(line1)
  1805. feed('o<esc>')
  1806. insert(line2)
  1807. ns = request('nvim_create_namespace', 'extmark-ui')
  1808. end)
  1809. it('sends and only sends ui-watched marks to ui', function()
  1810. screen = Screen.new(20, 4)
  1811. -- should send this
  1812. set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
  1813. -- should not send this
  1814. set_extmark(ns, marks[2], 0, 0, { ui_watched = false })
  1815. screen:expect({
  1816. grid = [[
  1817. non ui-watched line |
  1818. ui-watched lin^e |
  1819. {1:~ }|
  1820. |
  1821. ]],
  1822. extmarks = {
  1823. [2] = {
  1824. -- positioned at the end of the 2nd line
  1825. { 1000, ns, marks[1], 1, 16 },
  1826. },
  1827. },
  1828. })
  1829. end)
  1830. it('sends multiple ui-watched marks to ui', function()
  1831. screen = Screen.new(20, 4)
  1832. feed('15A!<Esc>')
  1833. -- should send all of these
  1834. set_extmark(ns, marks[1], 1, 0, { ui_watched = true, virt_text_pos = 'overlay' })
  1835. set_extmark(ns, marks[2], 1, 2, { ui_watched = true, virt_text_pos = 'overlay' })
  1836. set_extmark(ns, marks[3], 1, 4, { ui_watched = true, virt_text_pos = 'overlay' })
  1837. set_extmark(ns, marks[4], 1, 6, { ui_watched = true, virt_text_pos = 'overlay' })
  1838. set_extmark(ns, marks[5], 1, 8, { ui_watched = true })
  1839. screen:expect({
  1840. grid = [[
  1841. non ui-watched line |
  1842. ui-watched line!!!!!|
  1843. !!!!!!!!!^! |
  1844. |
  1845. ]],
  1846. extmarks = {
  1847. [2] = {
  1848. -- notification from 1st call
  1849. { 1000, ns, marks[1], 1, 0 },
  1850. -- notifications from 2nd call
  1851. { 1000, ns, marks[1], 1, 0 },
  1852. { 1000, ns, marks[2], 1, 2 },
  1853. -- notifications from 3rd call
  1854. { 1000, ns, marks[1], 1, 0 },
  1855. { 1000, ns, marks[2], 1, 2 },
  1856. { 1000, ns, marks[3], 1, 4 },
  1857. -- notifications from 4th call
  1858. { 1000, ns, marks[1], 1, 0 },
  1859. { 1000, ns, marks[2], 1, 2 },
  1860. { 1000, ns, marks[3], 1, 4 },
  1861. { 1000, ns, marks[4], 1, 6 },
  1862. -- final
  1863. -- overlay
  1864. { 1000, ns, marks[1], 1, 0 },
  1865. { 1000, ns, marks[2], 1, 2 },
  1866. { 1000, ns, marks[3], 1, 4 },
  1867. { 1000, ns, marks[4], 1, 6 },
  1868. -- eol
  1869. { 1000, ns, marks[5], 2, 11 },
  1870. },
  1871. },
  1872. })
  1873. end)
  1874. it('updates ui-watched marks', function()
  1875. screen = Screen.new(20, 4)
  1876. -- should send this
  1877. set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
  1878. -- should not send this
  1879. set_extmark(ns, marks[2], 0, 0, { ui_watched = false })
  1880. -- make some changes
  1881. insert(' update')
  1882. screen:expect({
  1883. grid = [[
  1884. non ui-watched line |
  1885. ui-watched linupdat^e|
  1886. e |
  1887. |
  1888. ]],
  1889. extmarks = {
  1890. [2] = {
  1891. -- positioned at the end of the 2nd line
  1892. { 1000, ns, marks[1], 1, 16 },
  1893. -- updated and wrapped to 3rd line
  1894. { 1000, ns, marks[1], 2, 2 },
  1895. },
  1896. },
  1897. })
  1898. feed('<c-e>')
  1899. screen:expect({
  1900. grid = [[
  1901. ui-watched linupdat^e|
  1902. e |
  1903. {1:~ }|
  1904. |
  1905. ]],
  1906. extmarks = {
  1907. [2] = {
  1908. -- positioned at the end of the 2nd line
  1909. { 1000, ns, marks[1], 1, 16 },
  1910. -- updated and wrapped to 3rd line
  1911. { 1000, ns, marks[1], 2, 2 },
  1912. -- scrolled up one line, should be handled by grid scroll
  1913. },
  1914. },
  1915. })
  1916. end)
  1917. it('sends ui-watched to splits', function()
  1918. screen = Screen.new(20, 8, { ext_multigrid = true })
  1919. -- should send this
  1920. set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
  1921. -- should not send this
  1922. set_extmark(ns, marks[2], 0, 0, { ui_watched = false })
  1923. command('split')
  1924. screen:expect({
  1925. grid = [[
  1926. ## grid 1
  1927. [4:--------------------]|*3
  1928. {3:[No Name] [+] }|
  1929. [2:--------------------]|*2
  1930. {2:[No Name] [+] }|
  1931. [3:--------------------]|
  1932. ## grid 2
  1933. non ui-watched line |
  1934. ui-watched line |
  1935. ## grid 3
  1936. |
  1937. ## grid 4
  1938. non ui-watched line |
  1939. ui-watched lin^e |
  1940. {1:~ }|
  1941. ]],
  1942. extmarks = {
  1943. [2] = {
  1944. -- positioned at the end of the 2nd line
  1945. { 1000, ns, marks[1], 1, 16 },
  1946. -- updated after split
  1947. { 1000, ns, marks[1], 1, 16 },
  1948. },
  1949. [4] = {
  1950. -- only after split
  1951. { 1001, ns, marks[1], 1, 16 },
  1952. },
  1953. },
  1954. })
  1955. -- make some changes
  1956. insert(' update')
  1957. screen:expect({
  1958. grid = [[
  1959. ## grid 1
  1960. [4:--------------------]|*3
  1961. {3:[No Name] [+] }|
  1962. [2:--------------------]|*2
  1963. {2:[No Name] [+] }|
  1964. [3:--------------------]|
  1965. ## grid 2
  1966. non ui-watched line |
  1967. ui-watched linupd{1:@@@}|
  1968. ## grid 3
  1969. |
  1970. ## grid 4
  1971. non ui-watched line |
  1972. ui-watched linupdat^e|
  1973. e |
  1974. ]],
  1975. extmarks = {
  1976. [2] = {
  1977. -- positioned at the end of the 2nd line
  1978. { 1000, ns, marks[1], 1, 16 },
  1979. -- updated after split
  1980. { 1000, ns, marks[1], 1, 16 },
  1981. },
  1982. [4] = {
  1983. { 1001, ns, marks[1], 1, 16 },
  1984. -- updated
  1985. { 1001, ns, marks[1], 2, 2 },
  1986. },
  1987. },
  1988. })
  1989. end)
  1990. end)