extmark_spec.lua 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175
  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, 0, 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. {7: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. {7:S1 }^aaa bbb ccc |
  1593. {7:S2S1}aaa bbb ccc |
  1594. {7:S2 }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('no crash checking invalidated flag of sign pair end key #31856', function()
  1647. api.nvim_buf_set_lines(0, 0, 1, false, { '', '' })
  1648. api.nvim_set_option_value('signcolumn', 'auto:2', {})
  1649. set_extmark(ns, 1, 0, 0, { sign_text = 'S1', invalidate = true, end_row = 0 })
  1650. set_extmark(ns, 2, 1, 0, { sign_text = 'S2', end_row = 1 })
  1651. command('d')
  1652. api.nvim_buf_clear_namespace(0, ns, 0, -1)
  1653. n.assert_alive()
  1654. end)
  1655. it('can set a URL', function()
  1656. local url1 = 'https://example.com'
  1657. local url2 = 'http://127.0.0.1'
  1658. set_extmark(ns, 1, 0, 0, { url = url1, end_col = 3 })
  1659. set_extmark(ns, 2, 0, 3, { url = url2, hl_group = 'Search', end_col = 5 })
  1660. local extmarks = get_extmarks(ns, 0, -1, { details = true })
  1661. eq(2, #extmarks)
  1662. eq(url1, extmarks[1][4].url)
  1663. eq(url2, extmarks[2][4].url)
  1664. eq('Search', extmarks[2][4].hl_group)
  1665. end)
  1666. it('respects priority', function()
  1667. screen = Screen.new(15, 10)
  1668. set_extmark(ns, marks[1], 0, 0, {
  1669. hl_group = 'Comment',
  1670. end_col = 2,
  1671. priority = 20,
  1672. })
  1673. -- Extmark defined after first extmark but has lower priority, first extmark "wins"
  1674. set_extmark(ns, marks[2], 0, 0, {
  1675. hl_group = 'String',
  1676. end_col = 2,
  1677. priority = 10,
  1678. })
  1679. screen:expect {
  1680. grid = [[
  1681. {1:12}34^5 |
  1682. {2:~ }|*8
  1683. |
  1684. ]],
  1685. attr_ids = {
  1686. [1] = { foreground = Screen.colors.Blue1 },
  1687. [2] = { foreground = Screen.colors.Blue1, bold = true },
  1688. },
  1689. }
  1690. end)
  1691. end)
  1692. describe('Extmarks buffer api with many marks', function()
  1693. local ns1
  1694. local ns2
  1695. local ns_marks = {}
  1696. before_each(function()
  1697. clear()
  1698. ns1 = request('nvim_create_namespace', 'ns1')
  1699. ns2 = request('nvim_create_namespace', 'ns2')
  1700. ns_marks = { [ns1] = {}, [ns2] = {} }
  1701. local lines = {}
  1702. for i = 1, 30 do
  1703. lines[#lines + 1] = string.rep('x ', i)
  1704. end
  1705. api.nvim_buf_set_lines(0, 0, -1, true, lines)
  1706. local ns = ns1
  1707. local q = 0
  1708. for i = 0, 29 do
  1709. for j = 0, i do
  1710. local id = set_extmark(ns, 0, i, j)
  1711. eq(nil, ns_marks[ns][id])
  1712. ok(id > 0)
  1713. ns_marks[ns][id] = { i, j }
  1714. ns = ns1 + ns2 - ns
  1715. q = q + 1
  1716. end
  1717. end
  1718. eq(233, #ns_marks[ns1])
  1719. eq(232, #ns_marks[ns2])
  1720. end)
  1721. local function get_marks(ns)
  1722. local mark_list = get_extmarks(ns, 0, -1)
  1723. local marks = {}
  1724. for _, mark in ipairs(mark_list) do
  1725. local id, row, col = unpack(mark)
  1726. eq(nil, marks[id], 'duplicate mark')
  1727. marks[id] = { row, col }
  1728. end
  1729. return marks
  1730. end
  1731. it('can get marks', function()
  1732. eq(ns_marks[ns1], get_marks(ns1))
  1733. eq(ns_marks[ns2], get_marks(ns2))
  1734. end)
  1735. it('can clear all marks in ns', function()
  1736. api.nvim_buf_clear_namespace(0, ns1, 0, -1)
  1737. eq({}, get_marks(ns1))
  1738. eq(ns_marks[ns2], get_marks(ns2))
  1739. api.nvim_buf_clear_namespace(0, ns2, 0, -1)
  1740. eq({}, get_marks(ns1))
  1741. eq({}, get_marks(ns2))
  1742. end)
  1743. it('can clear line range', function()
  1744. api.nvim_buf_clear_namespace(0, ns1, 10, 20)
  1745. for id, mark in pairs(ns_marks[ns1]) do
  1746. if 10 <= mark[1] and mark[1] < 20 then
  1747. ns_marks[ns1][id] = nil
  1748. end
  1749. end
  1750. eq(ns_marks[ns1], get_marks(ns1))
  1751. eq(ns_marks[ns2], get_marks(ns2))
  1752. api.nvim_buf_clear_namespace(0, ns1, 0, 10)
  1753. for id, mark in pairs(ns_marks[ns1]) do
  1754. if mark[1] < 10 then
  1755. ns_marks[ns1][id] = nil
  1756. end
  1757. end
  1758. eq(ns_marks[ns1], get_marks(ns1))
  1759. eq(ns_marks[ns2], get_marks(ns2))
  1760. api.nvim_buf_clear_namespace(0, ns1, 20, -1)
  1761. for id, mark in pairs(ns_marks[ns1]) do
  1762. if mark[1] >= 20 then
  1763. ns_marks[ns1][id] = nil
  1764. end
  1765. end
  1766. eq(ns_marks[ns1], get_marks(ns1))
  1767. eq(ns_marks[ns2], get_marks(ns2))
  1768. end)
  1769. it('can delete line', function()
  1770. feed('10Gdd')
  1771. for _, marks in pairs(ns_marks) do
  1772. for id, mark in pairs(marks) do
  1773. if mark[1] == 9 then
  1774. marks[id] = { 9, 0 }
  1775. elseif mark[1] >= 10 then
  1776. mark[1] = mark[1] - 1
  1777. end
  1778. end
  1779. end
  1780. eq(ns_marks[ns1], get_marks(ns1))
  1781. eq(ns_marks[ns2], get_marks(ns2))
  1782. end)
  1783. it('can delete lines', function()
  1784. feed('10G10dd')
  1785. for _, marks in pairs(ns_marks) do
  1786. for id, mark in pairs(marks) do
  1787. if 9 <= mark[1] and mark[1] < 19 then
  1788. marks[id] = { 9, 0 }
  1789. elseif mark[1] >= 19 then
  1790. mark[1] = mark[1] - 10
  1791. end
  1792. end
  1793. end
  1794. eq(ns_marks[ns1], get_marks(ns1))
  1795. eq(ns_marks[ns2], get_marks(ns2))
  1796. end)
  1797. it('can wipe buffer', function()
  1798. command('bwipe!')
  1799. eq({}, get_marks(ns1))
  1800. eq({}, get_marks(ns2))
  1801. end)
  1802. end)
  1803. describe('API/win_extmark', function()
  1804. local screen
  1805. local marks, line1, line2
  1806. local ns
  1807. before_each(function()
  1808. -- Initialize some namespaces and insert text into a buffer
  1809. marks = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
  1810. line1 = 'non ui-watched line'
  1811. line2 = 'ui-watched line'
  1812. clear()
  1813. insert(line1)
  1814. feed('o<esc>')
  1815. insert(line2)
  1816. ns = request('nvim_create_namespace', 'extmark-ui')
  1817. end)
  1818. it('sends and only sends ui-watched marks to ui', function()
  1819. screen = Screen.new(20, 4)
  1820. -- should send this
  1821. set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
  1822. -- should not send this
  1823. set_extmark(ns, marks[2], 0, 0, { ui_watched = false })
  1824. screen:expect({
  1825. grid = [[
  1826. non ui-watched line |
  1827. ui-watched lin^e |
  1828. {1:~ }|
  1829. |
  1830. ]],
  1831. extmarks = {
  1832. [2] = {
  1833. -- positioned at the end of the 2nd line
  1834. { 1000, ns, marks[1], 1, 16 },
  1835. },
  1836. },
  1837. })
  1838. end)
  1839. it('sends multiple ui-watched marks to ui', function()
  1840. screen = Screen.new(20, 4)
  1841. feed('15A!<Esc>')
  1842. -- should send all of these
  1843. set_extmark(ns, marks[1], 1, 0, { ui_watched = true, virt_text_pos = 'overlay' })
  1844. set_extmark(ns, marks[2], 1, 2, { ui_watched = true, virt_text_pos = 'overlay' })
  1845. set_extmark(ns, marks[3], 1, 4, { ui_watched = true, virt_text_pos = 'overlay' })
  1846. set_extmark(ns, marks[4], 1, 6, { ui_watched = true, virt_text_pos = 'overlay' })
  1847. set_extmark(ns, marks[5], 1, 8, { ui_watched = true })
  1848. screen:expect({
  1849. grid = [[
  1850. non ui-watched line |
  1851. ui-watched line!!!!!|
  1852. !!!!!!!!!^! |
  1853. |
  1854. ]],
  1855. extmarks = {
  1856. [2] = {
  1857. -- notification from 1st call
  1858. { 1000, ns, marks[1], 1, 0 },
  1859. -- notifications from 2nd call
  1860. { 1000, ns, marks[1], 1, 0 },
  1861. { 1000, ns, marks[2], 1, 2 },
  1862. -- notifications from 3rd call
  1863. { 1000, ns, marks[1], 1, 0 },
  1864. { 1000, ns, marks[2], 1, 2 },
  1865. { 1000, ns, marks[3], 1, 4 },
  1866. -- notifications from 4th call
  1867. { 1000, ns, marks[1], 1, 0 },
  1868. { 1000, ns, marks[2], 1, 2 },
  1869. { 1000, ns, marks[3], 1, 4 },
  1870. { 1000, ns, marks[4], 1, 6 },
  1871. -- final
  1872. -- overlay
  1873. { 1000, ns, marks[1], 1, 0 },
  1874. { 1000, ns, marks[2], 1, 2 },
  1875. { 1000, ns, marks[3], 1, 4 },
  1876. { 1000, ns, marks[4], 1, 6 },
  1877. -- eol
  1878. { 1000, ns, marks[5], 2, 11 },
  1879. },
  1880. },
  1881. })
  1882. end)
  1883. it('updates ui-watched marks', function()
  1884. screen = Screen.new(20, 4)
  1885. -- should send this
  1886. set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
  1887. -- should not send this
  1888. set_extmark(ns, marks[2], 0, 0, { ui_watched = false })
  1889. -- make some changes
  1890. insert(' update')
  1891. screen:expect({
  1892. grid = [[
  1893. non ui-watched line |
  1894. ui-watched linupdat^e|
  1895. e |
  1896. |
  1897. ]],
  1898. extmarks = {
  1899. [2] = {
  1900. -- positioned at the end of the 2nd line
  1901. { 1000, ns, marks[1], 1, 16 },
  1902. -- updated and wrapped to 3rd line
  1903. { 1000, ns, marks[1], 2, 2 },
  1904. },
  1905. },
  1906. })
  1907. feed('<c-e>')
  1908. screen:expect({
  1909. grid = [[
  1910. ui-watched linupdat^e|
  1911. e |
  1912. {1:~ }|
  1913. |
  1914. ]],
  1915. extmarks = {
  1916. [2] = {
  1917. -- positioned at the end of the 2nd line
  1918. { 1000, ns, marks[1], 1, 16 },
  1919. -- updated and wrapped to 3rd line
  1920. { 1000, ns, marks[1], 2, 2 },
  1921. -- scrolled up one line, should be handled by grid scroll
  1922. },
  1923. },
  1924. })
  1925. end)
  1926. it('sends ui-watched to splits', function()
  1927. screen = Screen.new(20, 8, { ext_multigrid = true })
  1928. -- should send this
  1929. set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
  1930. -- should not send this
  1931. set_extmark(ns, marks[2], 0, 0, { ui_watched = false })
  1932. command('split')
  1933. screen:expect({
  1934. grid = [[
  1935. ## grid 1
  1936. [4:--------------------]|*3
  1937. {3:[No Name] [+] }|
  1938. [2:--------------------]|*2
  1939. {2:[No Name] [+] }|
  1940. [3:--------------------]|
  1941. ## grid 2
  1942. non ui-watched line |
  1943. ui-watched line |
  1944. ## grid 3
  1945. |
  1946. ## grid 4
  1947. non ui-watched line |
  1948. ui-watched lin^e |
  1949. {1:~ }|
  1950. ]],
  1951. extmarks = {
  1952. [2] = {
  1953. -- positioned at the end of the 2nd line
  1954. { 1000, ns, marks[1], 1, 16 },
  1955. -- updated after split
  1956. { 1000, ns, marks[1], 1, 16 },
  1957. },
  1958. [4] = {
  1959. -- only after split
  1960. { 1001, ns, marks[1], 1, 16 },
  1961. },
  1962. },
  1963. })
  1964. -- make some changes
  1965. insert(' update')
  1966. screen:expect({
  1967. grid = [[
  1968. ## grid 1
  1969. [4:--------------------]|*3
  1970. {3:[No Name] [+] }|
  1971. [2:--------------------]|*2
  1972. {2:[No Name] [+] }|
  1973. [3:--------------------]|
  1974. ## grid 2
  1975. non ui-watched line |
  1976. ui-watched linupd{1:@@@}|
  1977. ## grid 3
  1978. |
  1979. ## grid 4
  1980. non ui-watched line |
  1981. ui-watched linupdat^e|
  1982. e |
  1983. ]],
  1984. extmarks = {
  1985. [2] = {
  1986. -- positioned at the end of the 2nd line
  1987. { 1000, ns, marks[1], 1, 16 },
  1988. -- updated after split
  1989. { 1000, ns, marks[1], 1, 16 },
  1990. },
  1991. [4] = {
  1992. { 1001, ns, marks[1], 1, 16 },
  1993. -- updated
  1994. { 1001, ns, marks[1], 2, 2 },
  1995. },
  1996. },
  1997. })
  1998. end)
  1999. end)