123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175 |
- local t = require('test.testutil')
- local n = require('test.functional.testnvim')()
- local Screen = require('test.functional.ui.screen')
- local request = n.request
- local eq = t.eq
- local ok = t.ok
- local pcall_err = t.pcall_err
- local insert = n.insert
- local feed = n.feed
- local clear = n.clear
- local command = n.command
- local exec = n.exec
- local api = n.api
- local assert_alive = n.assert_alive
- local function expect(contents)
- return eq(contents, n.curbuf_contents())
- end
- local function set_extmark(ns_id, id, line, col, opts)
- if opts == nil then
- opts = {}
- end
- if id ~= nil and id ~= 0 then
- opts.id = id
- end
- return api.nvim_buf_set_extmark(0, ns_id, line, col, opts)
- end
- local function get_extmarks(ns_id, start, end_, opts)
- if opts == nil then
- opts = {}
- end
- return api.nvim_buf_get_extmarks(0, ns_id, start, end_, opts)
- end
- local function get_extmark_by_id(ns_id, id, opts)
- if opts == nil then
- opts = {}
- end
- return api.nvim_buf_get_extmark_by_id(0, ns_id, id, opts)
- end
- local function check_undo_redo(ns, mark, sr, sc, er, ec) --s = start, e = end
- local rv = get_extmark_by_id(ns, mark)
- eq({ er, ec }, rv)
- feed('u')
- rv = get_extmark_by_id(ns, mark)
- eq({ sr, sc }, rv)
- feed('<c-r>')
- rv = get_extmark_by_id(ns, mark)
- eq({ er, ec }, rv)
- end
- local function batch_set(ns_id, positions)
- local ids = {}
- for _, pos in ipairs(positions) do
- table.insert(ids, set_extmark(ns_id, 0, pos[1], pos[2]))
- end
- return ids
- end
- local function batch_check(ns_id, ids, positions)
- local actual, expected = {}, {}
- for i, id in ipairs(ids) do
- expected[id] = positions[i]
- end
- for _, mark in pairs(get_extmarks(ns_id, 0, -1, {})) do
- actual[mark[1]] = { mark[2], mark[3] }
- end
- eq(expected, actual)
- end
- local function batch_check_undo_redo(ns_id, ids, before, after)
- batch_check(ns_id, ids, after)
- feed('u')
- batch_check(ns_id, ids, before)
- feed('<c-r>')
- batch_check(ns_id, ids, after)
- end
- describe('API/extmarks', function()
- local screen
- local marks, positions, init_text, row, col
- local ns, ns2
- before_each(function()
- -- Initialize some namespaces and insert 12345 into a buffer
- marks = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
- positions = { { 0, 0 }, { 0, 2 }, { 0, 3 } }
- init_text = '12345'
- row = 0
- col = 2
- clear()
- insert(init_text)
- ns = request('nvim_create_namespace', 'my-fancy-plugin')
- ns2 = request('nvim_create_namespace', 'my-fancy-plugin2')
- end)
- it('validation', function()
- eq(
- "Invalid 'end_col': expected Integer, got Array",
- pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = {}, end_row = 1 })
- )
- eq(
- "Invalid 'end_row': expected Integer, got Array",
- pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = {} })
- )
- eq(
- "Invalid 'virt_text_pos': expected String, got Integer",
- pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 0 })
- )
- eq(
- "Invalid 'virt_text_pos': 'foo'",
- pcall_err(set_extmark, ns, marks[2], 0, 0, { virt_text_pos = 'foo' })
- )
- eq(
- "Invalid 'hl_mode': expected String, got Integer",
- pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 0 })
- )
- eq("Invalid 'hl_mode': 'foo'", pcall_err(set_extmark, ns, marks[2], 0, 0, { hl_mode = 'foo' }))
- eq(
- "Invalid 'id': expected Integer, got Array",
- pcall_err(set_extmark, ns, {}, 0, 0, { end_col = 1, end_row = 1 })
- )
- eq(
- 'Invalid mark position: expected 2 Integer items',
- pcall_err(get_extmarks, ns, {}, { -1, -1 })
- )
- eq(
- 'Invalid mark position: expected mark id Integer or 2-item Array',
- pcall_err(get_extmarks, ns, true, { -1, -1 })
- )
- -- No memory leak with virt_text, virt_lines, sign_text
- eq(
- 'right_gravity is not a boolean',
- pcall_err(set_extmark, ns, marks[2], 0, 0, {
- virt_text = { { 'foo', 'Normal' } },
- virt_lines = { { { 'bar', 'Normal' } } },
- sign_text = 'a',
- right_gravity = 'baz',
- })
- )
- end)
- it('can end extranges past final newline using end_col = 0', function()
- set_extmark(ns, marks[1], 0, 0, {
- end_col = 0,
- end_row = 1,
- })
- eq(
- "Invalid 'end_col': out of range",
- pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = 1 })
- )
- end)
- it('can end extranges past final newline when strict mode is false', function()
- set_extmark(ns, marks[1], 0, 0, {
- end_col = 1,
- end_row = 1,
- strict = false,
- })
- end)
- it('can end extranges past final column when strict mode is false', function()
- set_extmark(ns, marks[1], 0, 0, {
- end_col = 6,
- end_row = 0,
- strict = false,
- })
- end)
- it('adds, updates and deletes marks', function()
- local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
- eq(marks[1], rv)
- rv = get_extmark_by_id(ns, marks[1])
- eq({ positions[1][1], positions[1][2] }, rv)
- -- Test adding a second mark on same row works
- rv = set_extmark(ns, marks[2], positions[2][1], positions[2][2])
- eq(marks[2], rv)
- -- Test an update, (same pos)
- rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
- eq(marks[1], rv)
- rv = get_extmark_by_id(ns, marks[2])
- eq({ positions[2][1], positions[2][2] }, rv)
- -- Test an update, (new pos)
- row = positions[1][1]
- col = positions[1][2] + 1
- rv = set_extmark(ns, marks[1], row, col)
- eq(marks[1], rv)
- rv = get_extmark_by_id(ns, marks[1])
- eq({ row, col }, rv)
- -- remove the test marks
- eq(true, api.nvim_buf_del_extmark(0, ns, marks[1]))
- eq(false, api.nvim_buf_del_extmark(0, ns, marks[1]))
- eq(true, api.nvim_buf_del_extmark(0, ns, marks[2]))
- eq(false, api.nvim_buf_del_extmark(0, ns, marks[3]))
- eq(false, api.nvim_buf_del_extmark(0, ns, 1000))
- end)
- it('can clear a specific namespace range', function()
- set_extmark(ns, 1, 0, 1)
- set_extmark(ns2, 1, 0, 1)
- -- force a new undo buffer
- feed('o<esc>')
- api.nvim_buf_clear_namespace(0, ns2, 0, -1)
- eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
- eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
- feed('u')
- eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
- eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
- feed('<c-r>')
- eq({ { 1, 0, 1 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
- eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
- end)
- it('can clear a namespace range using 0,-1', function()
- set_extmark(ns, 1, 0, 1)
- set_extmark(ns2, 1, 0, 1)
- -- force a new undo buffer
- feed('o<esc>')
- api.nvim_buf_clear_namespace(0, -1, 0, -1)
- eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
- eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
- feed('u')
- eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
- eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
- feed('<c-r>')
- eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
- eq({}, get_extmarks(ns2, { 0, 0 }, { -1, -1 }))
- end)
- it('can undo with extmarks (#25147)', function()
- feed('itest<esc>')
- set_extmark(ns, 1, 0, 0)
- set_extmark(ns, 2, 1, 0)
- eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
- feed('dd')
- eq({ { 1, 1, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
- api.nvim_buf_clear_namespace(0, ns, 0, -1)
- eq({}, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
- set_extmark(ns, 1, 0, 0, { right_gravity = false })
- set_extmark(ns, 2, 1, 0, { right_gravity = false })
- eq({ { 1, 0, 0 }, { 2, 1, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
- feed('u')
- eq({ { 1, 0, 0 }, { 2, 0, 0 } }, get_extmarks(ns, { 0, 0 }, { -1, -1 }))
- api.nvim_buf_clear_namespace(0, ns, 0, -1)
- end)
- it('querying for information and ranges', function()
- --marks = {1, 2, 3}
- --positions = {{0, 0,}, {0, 2}, {0, 3}}
- -- add some more marks
- for i, m in ipairs(marks) do
- if positions[i] ~= nil then
- local rv = set_extmark(ns, m, positions[i][1], positions[i][2])
- eq(m, rv)
- end
- end
- -- {0, 0} and {-1, -1} work as extreme values
- eq({ { 1, 0, 0 } }, get_extmarks(ns, { 0, 0 }, { 0, 0 }))
- eq({}, get_extmarks(ns, { -1, -1 }, { -1, -1 }))
- local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
- for i, m in ipairs(marks) do
- if positions[i] ~= nil then
- eq({ m, positions[i][1], positions[i][2] }, rv[i])
- end
- end
- -- 0 and -1 works as short hand extreme values
- eq({ { 1, 0, 0 } }, get_extmarks(ns, 0, 0))
- eq({}, get_extmarks(ns, -1, -1))
- rv = get_extmarks(ns, 0, -1)
- for i, m in ipairs(marks) do
- if positions[i] ~= nil then
- eq({ m, positions[i][1], positions[i][2] }, rv[i])
- end
- end
- -- next with mark id
- rv = get_extmarks(ns, marks[1], { -1, -1 }, { limit = 1 })
- eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
- rv = get_extmarks(ns, marks[2], { -1, -1 }, { limit = 1 })
- eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
- -- next with positional when mark exists at position
- rv = get_extmarks(ns, positions[1], { -1, -1 }, { limit = 1 })
- eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
- -- next with positional index (no mark at position)
- rv = get_extmarks(ns, { positions[1][1], positions[1][2] + 1 }, { -1, -1 }, { limit = 1 })
- eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
- -- next with Extremity index
- rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 })
- eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
- -- nextrange with mark id
- rv = get_extmarks(ns, marks[1], marks[3])
- eq({ marks[1], positions[1][1], positions[1][2] }, rv[1])
- eq({ marks[2], positions[2][1], positions[2][2] }, rv[2])
- -- nextrange with `limit`
- rv = get_extmarks(ns, marks[1], marks[3], { limit = 2 })
- eq(2, #rv)
- -- nextrange with positional when mark exists at position
- rv = get_extmarks(ns, positions[1], positions[3])
- eq({ marks[1], positions[1][1], positions[1][2] }, rv[1])
- eq({ marks[2], positions[2][1], positions[2][2] }, rv[2])
- rv = get_extmarks(ns, positions[2], positions[3])
- eq(2, #rv)
- -- nextrange with positional index (no mark at position)
- local lower = { positions[1][1], positions[2][2] - 1 }
- local upper = { positions[2][1], positions[3][2] - 1 }
- rv = get_extmarks(ns, lower, upper)
- eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
- lower = { positions[3][1], positions[3][2] + 1 }
- upper = { positions[3][1], positions[3][2] + 2 }
- rv = get_extmarks(ns, lower, upper)
- eq({}, rv)
- -- nextrange with extremity index
- lower = { positions[2][1], positions[2][2] + 1 }
- upper = { -1, -1 }
- rv = get_extmarks(ns, lower, upper)
- eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
- -- prev with mark id
- rv = get_extmarks(ns, marks[3], { 0, 0 }, { limit = 1 })
- eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
- rv = get_extmarks(ns, marks[2], { 0, 0 }, { limit = 1 })
- eq({ { marks[2], positions[2][1], positions[2][2] } }, rv)
- -- prev with positional when mark exists at position
- rv = get_extmarks(ns, positions[3], { 0, 0 }, { limit = 1 })
- eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
- -- prev with positional index (no mark at position)
- rv = get_extmarks(ns, { positions[1][1], positions[1][2] + 1 }, { 0, 0 }, { limit = 1 })
- eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
- -- prev with Extremity index
- rv = get_extmarks(ns, { -1, -1 }, { 0, 0 }, { limit = 1 })
- eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
- -- prevrange with mark id
- rv = get_extmarks(ns, marks[3], marks[1])
- eq({ marks[3], positions[3][1], positions[3][2] }, rv[1])
- eq({ marks[2], positions[2][1], positions[2][2] }, rv[2])
- eq({ marks[1], positions[1][1], positions[1][2] }, rv[3])
- -- prevrange with limit
- rv = get_extmarks(ns, marks[3], marks[1], { limit = 2 })
- eq(2, #rv)
- -- prevrange with positional when mark exists at position
- rv = get_extmarks(ns, positions[3], positions[1])
- eq({
- { marks[3], positions[3][1], positions[3][2] },
- { marks[2], positions[2][1], positions[2][2] },
- { marks[1], positions[1][1], positions[1][2] },
- }, rv)
- rv = get_extmarks(ns, positions[2], positions[1])
- eq(2, #rv)
- -- prevrange with positional index (no mark at position)
- lower = { positions[2][1], positions[2][2] + 1 }
- upper = { positions[3][1], positions[3][2] + 1 }
- rv = get_extmarks(ns, upper, lower)
- eq({ { marks[3], positions[3][1], positions[3][2] } }, rv)
- lower = { positions[3][1], positions[3][2] + 1 }
- upper = { positions[3][1], positions[3][2] + 2 }
- rv = get_extmarks(ns, upper, lower)
- eq({}, rv)
- -- prevrange with extremity index
- lower = { 0, 0 }
- upper = { positions[2][1], positions[2][2] - 1 }
- rv = get_extmarks(ns, upper, lower)
- eq({ { marks[1], positions[1][1], positions[1][2] } }, rv)
- end)
- it('querying for information with limit', function()
- -- add some more marks
- for i, m in ipairs(marks) do
- if positions[i] ~= nil then
- local rv = set_extmark(ns, m, positions[i][1], positions[i][2])
- eq(m, rv)
- end
- end
- local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 })
- eq(1, #rv)
- rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 2 })
- eq(2, #rv)
- rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 3 })
- eq(3, #rv)
- -- now in reverse
- rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 1 })
- eq(1, #rv)
- rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 2 })
- eq(2, #rv)
- rv = get_extmarks(ns, { 0, 0 }, { -1, -1 }, { limit = 3 })
- eq(3, #rv)
- end)
- it('get_marks works when mark col > upper col', function()
- feed('A<cr>12345<esc>')
- feed('A<cr>12345<esc>')
- set_extmark(ns, 10, 0, 2) -- this shouldn't be found
- set_extmark(ns, 11, 2, 1) -- this shouldn't be found
- set_extmark(ns, marks[1], 0, 4) -- check col > our upper bound
- set_extmark(ns, marks[2], 1, 1) -- check col < lower bound
- set_extmark(ns, marks[3], 2, 0) -- check is inclusive
- eq(
- { { marks[1], 0, 4 }, { marks[2], 1, 1 }, { marks[3], 2, 0 } },
- get_extmarks(ns, { 0, 3 }, { 2, 0 })
- )
- end)
- it('get_marks works in reverse when mark col < lower col', function()
- feed('A<cr>12345<esc>')
- feed('A<cr>12345<esc>')
- set_extmark(ns, 10, 0, 1) -- this shouldn't be found
- set_extmark(ns, 11, 2, 4) -- this shouldn't be found
- set_extmark(ns, marks[1], 2, 1) -- check col < our lower bound
- set_extmark(ns, marks[2], 1, 4) -- check col > upper bound
- set_extmark(ns, marks[3], 0, 2) -- check is inclusive
- local rv = get_extmarks(ns, { 2, 3 }, { 0, 2 })
- eq({ { marks[1], 2, 1 }, { marks[2], 1, 4 }, { marks[3], 0, 2 } }, rv)
- end)
- it('get_marks limit=0 returns nothing', function()
- set_extmark(ns, marks[1], positions[1][1], positions[1][2])
- local rv = get_extmarks(ns, { -1, -1 }, { -1, -1 }, { limit = 0 })
- eq({}, rv)
- end)
- it('marks move with line insertations', function()
- set_extmark(ns, marks[1], 0, 0)
- feed('yyP')
- check_undo_redo(ns, marks[1], 0, 0, 1, 0)
- end)
- it('marks move with multiline insertations', function()
- feed('a<cr>22<cr>33<esc>')
- set_extmark(ns, marks[1], 1, 1)
- feed('ggVGyP')
- check_undo_redo(ns, marks[1], 1, 1, 4, 1)
- end)
- it('marks move with line join', function()
- -- do_join in ops.c
- feed('a<cr>222<esc>')
- set_extmark(ns, marks[1], 1, 0)
- feed('ggJ')
- check_undo_redo(ns, marks[1], 1, 0, 0, 6)
- end)
- it('join works when no marks are present', function()
- screen = Screen.new(15, 10)
- feed('a<cr>1<esc>')
- feed('kJ')
- -- This shouldn't seg fault
- screen:expect([[
- 12345^ 1 |
- {1:~ }|*8
- |
- ]])
- end)
- it('marks move with multiline join', function()
- -- do_join in ops.c
- feed('a<cr>222<cr>333<cr>444<esc>')
- set_extmark(ns, marks[1], 3, 0)
- feed('2GVGJ')
- check_undo_redo(ns, marks[1], 3, 0, 1, 8)
- end)
- it('marks move with line deletes', function()
- feed('a<cr>222<cr>333<cr>444<esc>')
- set_extmark(ns, marks[1], 2, 1)
- feed('ggjdd')
- check_undo_redo(ns, marks[1], 2, 1, 1, 1)
- end)
- it('marks move with multiline deletes', function()
- feed('a<cr>222<cr>333<cr>444<esc>')
- set_extmark(ns, marks[1], 3, 0)
- feed('gg2dd')
- check_undo_redo(ns, marks[1], 3, 0, 1, 0)
- -- regression test, undoing multiline delete when mark is on row 1
- feed('ugg3dd')
- check_undo_redo(ns, marks[1], 3, 0, 0, 0)
- end)
- it('marks move with open line', function()
- -- open_line in change.c
- -- testing marks below are also moved
- feed('yyP')
- set_extmark(ns, marks[1], 0, 4)
- set_extmark(ns, marks[2], 1, 4)
- feed('1G<s-o><esc>')
- check_undo_redo(ns, marks[1], 0, 4, 1, 4)
- check_undo_redo(ns, marks[2], 1, 4, 2, 4)
- feed('2Go<esc>')
- check_undo_redo(ns, marks[1], 1, 4, 1, 4)
- check_undo_redo(ns, marks[2], 2, 4, 3, 4)
- end)
- it('marks move with char inserts', function()
- -- insertchar in edit.c (the ins_str branch)
- screen = Screen.new(15, 10)
- set_extmark(ns, marks[1], 0, 3)
- feed('0')
- insert('abc')
- screen:expect([[
- ab^c12345 |
- {1:~ }|*8
- |
- ]])
- local rv = get_extmark_by_id(ns, marks[1])
- eq({ 0, 6 }, rv)
- check_undo_redo(ns, marks[1], 0, 3, 0, 6)
- end)
- -- gravity right as definted in tk library
- it('marks have gravity right', function()
- -- insertchar in edit.c (the ins_str branch)
- set_extmark(ns, marks[1], 0, 2)
- feed('03l')
- insert('X')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- -- check multibyte chars
- feed('03l<esc>')
- insert('~~')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- end)
- it('we can insert multibyte chars', function()
- -- insertchar in edit.c
- feed('a<cr>12345<esc>')
- set_extmark(ns, marks[1], 1, 2)
- -- Insert a fullwidth (two col) tilde, NICE
- feed('0i~<esc>')
- check_undo_redo(ns, marks[1], 1, 2, 1, 5)
- end)
- it('marks move with blockwise inserts', function()
- -- op_insert in ops.c
- feed('a<cr>12345<esc>')
- set_extmark(ns, marks[1], 1, 2)
- feed('0<c-v>lkI9<esc>')
- check_undo_redo(ns, marks[1], 1, 2, 1, 3)
- end)
- it('marks move with line splits (using enter)', function()
- -- open_line in change.c
- -- testing marks below are also moved
- feed('yyP')
- set_extmark(ns, marks[1], 0, 4)
- set_extmark(ns, marks[2], 1, 4)
- feed('1Gla<cr><esc>')
- check_undo_redo(ns, marks[1], 0, 4, 1, 2)
- check_undo_redo(ns, marks[2], 1, 4, 2, 4)
- end)
- it('marks at last line move on insert new line', function()
- -- open_line in change.c
- set_extmark(ns, marks[1], 0, 4)
- feed('0i<cr><esc>')
- check_undo_redo(ns, marks[1], 0, 4, 1, 4)
- end)
- it('yet again marks move with line splits', function()
- -- the first test above wasn't catching all errors..
- feed('A67890<esc>')
- set_extmark(ns, marks[1], 0, 4)
- feed('04li<cr><esc>')
- check_undo_redo(ns, marks[1], 0, 4, 1, 0)
- end)
- it('and one last time line splits...', function()
- set_extmark(ns, marks[1], 0, 1)
- set_extmark(ns, marks[2], 0, 2)
- feed('02li<cr><esc>')
- check_undo_redo(ns, marks[1], 0, 1, 0, 1)
- check_undo_redo(ns, marks[2], 0, 2, 1, 0)
- end)
- it('multiple marks move with mark splits', function()
- set_extmark(ns, marks[1], 0, 1)
- set_extmark(ns, marks[2], 0, 3)
- feed('0li<cr><esc>')
- check_undo_redo(ns, marks[1], 0, 1, 1, 0)
- check_undo_redo(ns, marks[2], 0, 3, 1, 2)
- end)
- it('deleting right before a mark works', function()
- -- op_delete in ops.c
- set_extmark(ns, marks[1], 0, 2)
- feed('0lx')
- check_undo_redo(ns, marks[1], 0, 2, 0, 1)
- end)
- it('deleting right after a mark works', function()
- -- op_delete in ops.c
- set_extmark(ns, marks[1], 0, 2)
- feed('02lx')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- end)
- it('marks move with char deletes', function()
- -- op_delete in ops.c
- set_extmark(ns, marks[1], 0, 2)
- feed('02dl')
- check_undo_redo(ns, marks[1], 0, 2, 0, 0)
- -- from the other side (nothing should happen)
- feed('$x')
- check_undo_redo(ns, marks[1], 0, 0, 0, 0)
- end)
- it('marks move with char deletes over a range', function()
- -- op_delete in ops.c
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 0, 3)
- feed('0l3dl<esc>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 1)
- check_undo_redo(ns, marks[2], 0, 3, 0, 1)
- -- delete 1, nothing should happen to our marks
- feed('u')
- feed('$x')
- check_undo_redo(ns, marks[2], 0, 3, 0, 3)
- end)
- it('deleting marks at end of line works', function()
- set_extmark(ns, marks[1], 0, 4)
- feed('$x')
- check_undo_redo(ns, marks[1], 0, 4, 0, 4)
- -- check the copy happened correctly on delete at eol
- feed('$x')
- check_undo_redo(ns, marks[1], 0, 4, 0, 3)
- feed('u')
- check_undo_redo(ns, marks[1], 0, 4, 0, 4)
- end)
- it('marks move with blockwise deletes', function()
- -- op_delete in ops.c
- feed('a<cr>12345<esc>')
- set_extmark(ns, marks[1], 1, 4)
- feed('h<c-v>hhkd')
- check_undo_redo(ns, marks[1], 1, 4, 1, 1)
- end)
- it('marks move with blockwise deletes over a range', function()
- -- op_delete in ops.c
- feed('a<cr>12345<esc>')
- set_extmark(ns, marks[1], 0, 1)
- set_extmark(ns, marks[2], 0, 3)
- set_extmark(ns, marks[3], 1, 2)
- feed('0<c-v>k3lx')
- check_undo_redo(ns, marks[1], 0, 1, 0, 0)
- check_undo_redo(ns, marks[2], 0, 3, 0, 0)
- check_undo_redo(ns, marks[3], 1, 2, 1, 0)
- -- delete 1, nothing should happen to our marks
- feed('u')
- feed('$<c-v>jx')
- check_undo_redo(ns, marks[2], 0, 3, 0, 3)
- check_undo_redo(ns, marks[3], 1, 2, 1, 2)
- end)
- it('works with char deletes over multilines', function()
- feed('a<cr>12345<cr>test-me<esc>')
- set_extmark(ns, marks[1], 2, 5)
- feed('gg')
- feed('dv?-m?<cr>')
- check_undo_redo(ns, marks[1], 2, 5, 0, 0)
- end)
- it('marks outside of deleted range move with visual char deletes', function()
- -- op_delete in ops.c
- set_extmark(ns, marks[1], 0, 3)
- feed('0vx<esc>')
- check_undo_redo(ns, marks[1], 0, 3, 0, 2)
- feed('u')
- feed('0vlx<esc>')
- check_undo_redo(ns, marks[1], 0, 3, 0, 1)
- feed('u')
- feed('0v2lx<esc>')
- check_undo_redo(ns, marks[1], 0, 3, 0, 0)
- -- from the other side (nothing should happen)
- feed('$vx')
- check_undo_redo(ns, marks[1], 0, 0, 0, 0)
- end)
- it('marks outside of deleted range move with char deletes', function()
- -- op_delete in ops.c
- set_extmark(ns, marks[1], 0, 3)
- feed('0x<esc>')
- check_undo_redo(ns, marks[1], 0, 3, 0, 2)
- feed('u')
- feed('02x<esc>')
- check_undo_redo(ns, marks[1], 0, 3, 0, 1)
- feed('u')
- feed('0v3lx<esc>')
- check_undo_redo(ns, marks[1], 0, 3, 0, 0)
- -- from the other side (nothing should happen)
- feed('u')
- feed('$vx')
- check_undo_redo(ns, marks[1], 0, 3, 0, 3)
- end)
- it('marks move with P(backward) paste', function()
- -- do_put in ops.c
- feed('0iabc<esc>')
- set_extmark(ns, marks[1], 0, 7)
- feed('0veyP')
- check_undo_redo(ns, marks[1], 0, 7, 0, 15)
- end)
- it('marks move with p(forward) paste', function()
- -- do_put in ops.c
- feed('0iabc<esc>')
- set_extmark(ns, marks[1], 0, 7)
- feed('0veyp')
- check_undo_redo(ns, marks[1], 0, 7, 0, 15)
- end)
- it('marks move with blockwise P(backward) paste', function()
- -- do_put in ops.c
- feed('a<cr>12345<esc>')
- set_extmark(ns, marks[1], 1, 4)
- feed('<c-v>hhkyP<esc>')
- check_undo_redo(ns, marks[1], 1, 4, 1, 7)
- end)
- it('marks move with blockwise p(forward) paste', function()
- -- do_put in ops.c
- feed('a<cr>12345<esc>')
- set_extmark(ns, marks[1], 1, 4)
- feed('<c-v>hhkyp<esc>')
- check_undo_redo(ns, marks[1], 1, 4, 1, 7)
- end)
- describe('multiline regions', function()
- before_each(function()
- feed('dd')
- -- Achtung: code has been spiced with some unicode,
- -- to make life more interesting.
- -- luacheck whines about TABs inside strings for whatever reason.
- -- luacheck: push ignore 621
- insert([[
- static int nlua_rpcrequest(lua_State *lstate)
- {
- Ïf (!nlua_is_deferred_safe(lstate)) {
- // strictly not allowed
- Яetörn luaL_error(lstate, e_fast_api_disabled, "rpcrequest");
- }
- return nlua_rpc(lstate, true);
- }]])
- -- luacheck: pop
- end)
- it('delete', function()
- local pos1 = {
- { 2, 4 },
- { 2, 12 },
- { 2, 13 },
- { 2, 14 },
- { 2, 25 },
- { 4, 8 },
- { 4, 10 },
- { 4, 20 },
- { 5, 3 },
- { 6, 10 },
- }
- local ids = batch_set(ns, pos1)
- batch_check(ns, ids, pos1)
- feed('3Gfiv2+ftd')
- batch_check_undo_redo(ns, ids, pos1, {
- { 2, 4 },
- { 2, 12 },
- { 2, 13 },
- { 2, 13 },
- { 2, 13 },
- { 2, 13 },
- { 2, 15 },
- { 2, 25 },
- { 3, 3 },
- { 4, 10 },
- })
- end)
- it('can get overlapping extmarks', function()
- set_extmark(ns, 1, 0, 0, { end_row = 5, end_col = 0 })
- set_extmark(ns, 2, 2, 5, { end_row = 2, end_col = 30 })
- set_extmark(ns, 3, 0, 5, { end_row = 2, end_col = 10 })
- set_extmark(ns, 4, 0, 0, { end_row = 1, end_col = 0 })
- eq({ { 2, 2, 5 } }, get_extmarks(ns, { 2, 0 }, { 2, -1 }, { overlap = false }))
- eq(
- { { 1, 0, 0 }, { 3, 0, 5 }, { 2, 2, 5 } },
- get_extmarks(ns, { 2, 0 }, { 2, -1 }, { overlap = true })
- )
- end)
- end)
- it('replace works', function()
- set_extmark(ns, marks[1], 0, 2)
- feed('0r2')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- end)
- it('blockwise replace works', function()
- feed('a<cr>12345<esc>')
- set_extmark(ns, marks[1], 0, 2)
- feed('0<c-v>llkr1<esc>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 3)
- end)
- it('shift line', function()
- -- shift_line in ops.c
- feed(':set shiftwidth=4<cr><esc>')
- set_extmark(ns, marks[1], 0, 2)
- feed('0>>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 6)
- expect(' 12345')
- feed('>>')
- -- this is counter-intuitive. But what happens
- -- is that 4 spaces gets extended to one tab (== 8 spaces)
- check_undo_redo(ns, marks[1], 0, 6, 0, 3)
- expect('\t12345')
- feed('<LT><LT>') -- have to escape, same as <<
- check_undo_redo(ns, marks[1], 0, 3, 0, 6)
- end)
- it('blockwise shift', function()
- -- shift_block in ops.c
- feed(':set shiftwidth=4<cr><esc>')
- feed('a<cr>12345<esc>')
- set_extmark(ns, marks[1], 1, 2)
- feed('0<c-v>k>')
- check_undo_redo(ns, marks[1], 1, 2, 1, 6)
- feed('<c-v>j>')
- expect('\t12345\n\t12345')
- check_undo_redo(ns, marks[1], 1, 6, 1, 3)
- feed('<c-v>j<LT>')
- check_undo_redo(ns, marks[1], 1, 3, 1, 6)
- end)
- it('tab works with expandtab', function()
- -- ins_tab in edit.c
- feed(':set expandtab<cr><esc>')
- feed(':set shiftwidth=2<cr><esc>')
- set_extmark(ns, marks[1], 0, 2)
- feed('0i<tab><tab><esc>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 6)
- end)
- it('tabs work', function()
- -- ins_tab in edit.c
- feed(':set noexpandtab<cr><esc>')
- feed(':set shiftwidth=2<cr><esc>')
- feed(':set softtabstop=2<cr><esc>')
- feed(':set tabstop=8<cr><esc>')
- set_extmark(ns, marks[1], 0, 2)
- feed('0i<tab><esc>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 4)
- feed('0iX<tab><esc>')
- check_undo_redo(ns, marks[1], 0, 4, 0, 6)
- end)
- it('marks move when using :move', function()
- set_extmark(ns, marks[1], 0, 0)
- feed('A<cr>2<esc>:1move 2<cr><esc>')
- check_undo_redo(ns, marks[1], 0, 0, 1, 0)
- -- test codepath when moving lines up
- feed(':2move 0<cr><esc>')
- check_undo_redo(ns, marks[1], 1, 0, 0, 0)
- end)
- it('marks move when using :move part 2', function()
- -- make sure we didn't get lucky with the math...
- feed('A<cr>2<cr>3<cr>4<cr>5<cr>6<esc>')
- set_extmark(ns, marks[1], 1, 0)
- feed(':2,3move 5<cr><esc>')
- check_undo_redo(ns, marks[1], 1, 0, 3, 0)
- -- test codepath when moving lines up
- feed(':4,5move 1<cr><esc>')
- check_undo_redo(ns, marks[1], 3, 0, 1, 0)
- end)
- it('undo and redo of set and unset marks', function()
- -- Force a new undo head
- feed('o<esc>')
- set_extmark(ns, marks[1], 0, 1)
- feed('o<esc>')
- set_extmark(ns, marks[2], 0, -1)
- set_extmark(ns, marks[3], 0, -1)
- feed('u')
- local rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
- eq(3, #rv)
- feed('<c-r>')
- rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
- eq(3, #rv)
- -- Test updates
- feed('o<esc>')
- set_extmark(ns, marks[1], positions[1][1], positions[1][2])
- rv = get_extmarks(ns, marks[1], marks[1], { limit = 1 })
- eq(1, #rv)
- feed('u')
- feed('<c-r>')
- -- old value is NOT kept in history
- check_undo_redo(
- ns,
- marks[1],
- positions[1][1],
- positions[1][2],
- positions[1][1],
- positions[1][2]
- )
- -- Test unset
- feed('o<esc>')
- api.nvim_buf_del_extmark(0, ns, marks[3])
- feed('u')
- rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
- -- undo does NOT restore deleted marks
- eq(2, #rv)
- feed('<c-r>')
- rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
- eq(2, #rv)
- end)
- it('undo and redo of marks deleted during edits', function()
- -- test extmark_adjust
- feed('A<cr>12345<esc>')
- set_extmark(ns, marks[1], 1, 2)
- feed('dd')
- check_undo_redo(ns, marks[1], 1, 2, 1, 0)
- end)
- it('namespaces work properly', function()
- local rv = set_extmark(ns, marks[1], positions[1][1], positions[1][2])
- eq(1, rv)
- rv = set_extmark(ns2, marks[1], positions[1][1], positions[1][2])
- eq(1, rv)
- rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
- eq(1, #rv)
- rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 })
- eq(1, #rv)
- -- Set more marks for testing the ranges
- set_extmark(ns, marks[2], positions[2][1], positions[2][2])
- set_extmark(ns, marks[3], positions[3][1], positions[3][2])
- set_extmark(ns2, marks[2], positions[2][1], positions[2][2])
- set_extmark(ns2, marks[3], positions[3][1], positions[3][2])
- -- get_next (limit set)
- rv = get_extmarks(ns, { 0, 0 }, positions[2], { limit = 1 })
- eq(1, #rv)
- rv = get_extmarks(ns2, { 0, 0 }, positions[2], { limit = 1 })
- eq(1, #rv)
- -- get_prev (limit set)
- rv = get_extmarks(ns, positions[1], { 0, 0 }, { limit = 1 })
- eq(1, #rv)
- rv = get_extmarks(ns2, positions[1], { 0, 0 }, { limit = 1 })
- eq(1, #rv)
- -- get_next (no limit)
- rv = get_extmarks(ns, positions[1], positions[2])
- eq(2, #rv)
- rv = get_extmarks(ns2, positions[1], positions[2])
- eq(2, #rv)
- -- get_prev (no limit)
- rv = get_extmarks(ns, positions[2], positions[1])
- eq(2, #rv)
- rv = get_extmarks(ns2, positions[2], positions[1])
- eq(2, #rv)
- api.nvim_buf_del_extmark(0, ns, marks[1])
- rv = get_extmarks(ns, { 0, 0 }, { -1, -1 })
- eq(2, #rv)
- api.nvim_buf_del_extmark(0, ns2, marks[1])
- rv = get_extmarks(ns2, { 0, 0 }, { -1, -1 })
- eq(2, #rv)
- end)
- it('mark set can create unique identifiers', function()
- -- create mark with id 1
- eq(1, set_extmark(ns, 1, positions[1][1], positions[1][2]))
- -- ask for unique id, it should be the next one, i e 2
- eq(2, set_extmark(ns, 0, positions[1][1], positions[1][2]))
- eq(3, set_extmark(ns, 3, positions[2][1], positions[2][2]))
- eq(4, set_extmark(ns, 0, positions[1][1], positions[1][2]))
- -- mixing manual and allocated id:s are not recommended, but it should
- -- do something reasonable
- eq(6, set_extmark(ns, 6, positions[2][1], positions[2][2]))
- eq(7, set_extmark(ns, 0, positions[1][1], positions[1][2]))
- eq(8, set_extmark(ns, 0, positions[1][1], positions[1][2]))
- end)
- it('auto indenting with enter works', function()
- -- op_reindent in ops.c
- feed(':set cindent<cr><esc>')
- feed(':set autoindent<cr><esc>')
- feed(':set shiftwidth=2<cr><esc>')
- feed('0iint <esc>A {1M1<esc>b<esc>')
- -- Set the mark on the M, should move..
- set_extmark(ns, marks[1], 0, 12)
- -- Set the mark before the cursor, should stay there
- set_extmark(ns, marks[2], 0, 10)
- feed('i<cr><esc>')
- local rv = get_extmark_by_id(ns, marks[1])
- eq({ 1, 3 }, rv)
- rv = get_extmark_by_id(ns, marks[2])
- eq({ 0, 10 }, rv)
- check_undo_redo(ns, marks[1], 0, 12, 1, 3)
- end)
- it('auto indenting entire line works', function()
- feed(':set cindent<cr><esc>')
- feed(':set autoindent<cr><esc>')
- feed(':set shiftwidth=2<cr><esc>')
- -- <c-f> will force an indent of 2
- feed('0iint <esc>A {<cr><esc>0i1M1<esc>')
- set_extmark(ns, marks[1], 1, 1)
- feed('0i<c-f><esc>')
- local rv = get_extmark_by_id(ns, marks[1])
- eq({ 1, 3 }, rv)
- check_undo_redo(ns, marks[1], 1, 1, 1, 3)
- -- now check when cursor at eol
- feed('uA<c-f><esc>')
- rv = get_extmark_by_id(ns, marks[1])
- eq({ 1, 3 }, rv)
- end)
- it('removing auto indenting with <C-D> works', function()
- feed(':set cindent<cr><esc>')
- feed(':set autoindent<cr><esc>')
- feed(':set shiftwidth=2<cr><esc>')
- feed('0i<tab><esc>')
- set_extmark(ns, marks[1], 0, 3)
- feed('bi<c-d><esc>')
- local rv = get_extmark_by_id(ns, marks[1])
- eq({ 0, 1 }, rv)
- check_undo_redo(ns, marks[1], 0, 3, 0, 1)
- -- check when cursor at eol
- feed('uA<c-d><esc>')
- rv = get_extmark_by_id(ns, marks[1])
- eq({ 0, 1 }, rv)
- end)
- it('indenting multiple lines with = works', function()
- feed(':set cindent<cr><esc>')
- feed(':set autoindent<cr><esc>')
- feed(':set shiftwidth=2<cr><esc>')
- feed('0iint <esc>A {<cr><bs>1M1<cr><bs>2M2<esc>')
- set_extmark(ns, marks[1], 1, 1)
- set_extmark(ns, marks[2], 2, 1)
- feed('=gg')
- check_undo_redo(ns, marks[1], 1, 1, 1, 3)
- check_undo_redo(ns, marks[2], 2, 1, 2, 5)
- end)
- it('substitutes by deleting inside the replace matches', function()
- -- do_sub in ex_cmds.c
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 0, 3)
- feed(':s/34/xx<cr>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 4)
- check_undo_redo(ns, marks[2], 0, 3, 0, 4)
- end)
- it('substitutes when insert text > deleted', function()
- -- do_sub in ex_cmds.c
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 0, 3)
- feed(':s/34/xxx<cr>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 5)
- check_undo_redo(ns, marks[2], 0, 3, 0, 5)
- end)
- it('substitutes when marks around eol', function()
- -- do_sub in ex_cmds.c
- set_extmark(ns, marks[1], 0, 4)
- set_extmark(ns, marks[2], 0, 5)
- feed(':s/5/xxx<cr>')
- check_undo_redo(ns, marks[1], 0, 4, 0, 7)
- check_undo_redo(ns, marks[2], 0, 5, 0, 7)
- end)
- it('substitutes over range insert text > deleted', function()
- -- do_sub in ex_cmds.c
- feed('A<cr>x34xx<esc>')
- feed('A<cr>xxx34<esc>')
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 1, 1)
- set_extmark(ns, marks[3], 2, 4)
- feed(':1,3s/34/xxx<cr><esc>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 5)
- check_undo_redo(ns, marks[2], 1, 1, 1, 4)
- check_undo_redo(ns, marks[3], 2, 4, 2, 6)
- end)
- it('substitutes multiple matches in a line', function()
- -- do_sub in ex_cmds.c
- feed('ddi3x3x3<esc>')
- set_extmark(ns, marks[1], 0, 0)
- set_extmark(ns, marks[2], 0, 2)
- set_extmark(ns, marks[3], 0, 4)
- feed(':s/3/yy/g<cr><esc>')
- check_undo_redo(ns, marks[1], 0, 0, 0, 2)
- check_undo_redo(ns, marks[2], 0, 2, 0, 5)
- check_undo_redo(ns, marks[3], 0, 4, 0, 8)
- end)
- it('substitutes over multiple lines with newline in pattern', function()
- feed('A<cr>67890<cr>xx<esc>')
- set_extmark(ns, marks[1], 0, 3)
- set_extmark(ns, marks[2], 0, 4)
- set_extmark(ns, marks[3], 1, 0)
- set_extmark(ns, marks[4], 1, 5)
- set_extmark(ns, marks[5], 2, 0)
- feed([[:1,2s:5\n:5 <cr>]])
- check_undo_redo(ns, marks[1], 0, 3, 0, 3)
- check_undo_redo(ns, marks[2], 0, 4, 0, 6)
- check_undo_redo(ns, marks[3], 1, 0, 0, 6)
- check_undo_redo(ns, marks[4], 1, 5, 0, 11)
- check_undo_redo(ns, marks[5], 2, 0, 1, 0)
- end)
- it('inserting', function()
- feed('A<cr>67890<cr>xx<esc>')
- set_extmark(ns, marks[1], 0, 3)
- set_extmark(ns, marks[2], 0, 4)
- set_extmark(ns, marks[3], 1, 0)
- set_extmark(ns, marks[4], 1, 5)
- set_extmark(ns, marks[5], 2, 0)
- set_extmark(ns, marks[6], 1, 2)
- feed([[:1,2s:5\n67:X<cr>]])
- check_undo_redo(ns, marks[1], 0, 3, 0, 3)
- check_undo_redo(ns, marks[2], 0, 4, 0, 5)
- check_undo_redo(ns, marks[3], 1, 0, 0, 5)
- check_undo_redo(ns, marks[4], 1, 5, 0, 8)
- check_undo_redo(ns, marks[5], 2, 0, 1, 0)
- check_undo_redo(ns, marks[6], 1, 2, 0, 5)
- end)
- it('substitutes with multiple newlines in pattern', function()
- feed('A<cr>67890<cr>xx<esc>')
- set_extmark(ns, marks[1], 0, 4)
- set_extmark(ns, marks[2], 0, 5)
- set_extmark(ns, marks[3], 1, 0)
- set_extmark(ns, marks[4], 1, 5)
- set_extmark(ns, marks[5], 2, 0)
- feed([[:1,2s:\n.*\n:X<cr>]])
- check_undo_redo(ns, marks[1], 0, 4, 0, 4)
- check_undo_redo(ns, marks[2], 0, 5, 0, 6)
- check_undo_redo(ns, marks[3], 1, 0, 0, 6)
- check_undo_redo(ns, marks[4], 1, 5, 0, 6)
- check_undo_redo(ns, marks[5], 2, 0, 0, 6)
- end)
- it('substitutes over multiple lines with replace in substitution', function()
- feed('A<cr>67890<cr>xx<esc>')
- set_extmark(ns, marks[1], 0, 1)
- set_extmark(ns, marks[2], 0, 2)
- set_extmark(ns, marks[3], 0, 4)
- set_extmark(ns, marks[4], 1, 0)
- set_extmark(ns, marks[5], 2, 0)
- feed([[:1,2s:3:\r<cr>]])
- check_undo_redo(ns, marks[1], 0, 1, 0, 1)
- check_undo_redo(ns, marks[2], 0, 2, 1, 0)
- check_undo_redo(ns, marks[3], 0, 4, 1, 1)
- check_undo_redo(ns, marks[4], 1, 0, 2, 0)
- check_undo_redo(ns, marks[5], 2, 0, 3, 0)
- feed('u')
- feed([[:1,2s:3:\rxx<cr>]])
- eq({ 1, 3 }, get_extmark_by_id(ns, marks[3]))
- end)
- it('substitutes over multiple lines with replace in substitution', function()
- feed('A<cr>x3<cr>xx<esc>')
- set_extmark(ns, marks[1], 1, 0)
- set_extmark(ns, marks[2], 1, 1)
- set_extmark(ns, marks[3], 1, 2)
- feed([[:2,2s:3:\r<cr>]])
- check_undo_redo(ns, marks[1], 1, 0, 1, 0)
- check_undo_redo(ns, marks[2], 1, 1, 2, 0)
- check_undo_redo(ns, marks[3], 1, 2, 2, 0)
- end)
- it('substitutes over multiple lines with replace in substitution', function()
- feed('A<cr>x3<cr>xx<esc>')
- set_extmark(ns, marks[1], 0, 1)
- set_extmark(ns, marks[2], 0, 2)
- set_extmark(ns, marks[3], 0, 4)
- set_extmark(ns, marks[4], 1, 1)
- set_extmark(ns, marks[5], 2, 0)
- feed([[:1,2s:3:\r<cr>]])
- check_undo_redo(ns, marks[1], 0, 1, 0, 1)
- check_undo_redo(ns, marks[2], 0, 2, 1, 0)
- check_undo_redo(ns, marks[3], 0, 4, 1, 1)
- check_undo_redo(ns, marks[4], 1, 1, 3, 0)
- check_undo_redo(ns, marks[5], 2, 0, 4, 0)
- feed('u')
- feed([[:1,2s:3:\rxx<cr>]])
- check_undo_redo(ns, marks[3], 0, 4, 1, 3)
- end)
- it('substitutes with newline in match and sub, delta is 0', function()
- feed('A<cr>67890<cr>xx<esc>')
- set_extmark(ns, marks[1], 0, 3)
- set_extmark(ns, marks[2], 0, 4)
- set_extmark(ns, marks[3], 0, 5)
- set_extmark(ns, marks[4], 1, 0)
- set_extmark(ns, marks[5], 1, 5)
- set_extmark(ns, marks[6], 2, 0)
- feed([[:1,1s:5\n:\r<cr>]])
- check_undo_redo(ns, marks[1], 0, 3, 0, 3)
- check_undo_redo(ns, marks[2], 0, 4, 1, 0)
- check_undo_redo(ns, marks[3], 0, 5, 1, 0)
- check_undo_redo(ns, marks[4], 1, 0, 1, 0)
- check_undo_redo(ns, marks[5], 1, 5, 1, 5)
- check_undo_redo(ns, marks[6], 2, 0, 2, 0)
- end)
- it('substitutes with newline in match and sub, delta > 0', function()
- feed('A<cr>67890<cr>xx<esc>')
- set_extmark(ns, marks[1], 0, 3)
- set_extmark(ns, marks[2], 0, 4)
- set_extmark(ns, marks[3], 0, 5)
- set_extmark(ns, marks[4], 1, 0)
- set_extmark(ns, marks[5], 1, 5)
- set_extmark(ns, marks[6], 2, 0)
- feed([[:1,1s:5\n:\r\r<cr>]])
- check_undo_redo(ns, marks[1], 0, 3, 0, 3)
- check_undo_redo(ns, marks[2], 0, 4, 2, 0)
- check_undo_redo(ns, marks[3], 0, 5, 2, 0)
- check_undo_redo(ns, marks[4], 1, 0, 2, 0)
- check_undo_redo(ns, marks[5], 1, 5, 2, 5)
- check_undo_redo(ns, marks[6], 2, 0, 3, 0)
- end)
- it('substitutes with newline in match and sub, delta < 0', function()
- feed('A<cr>67890<cr>xx<cr>xx<esc>')
- set_extmark(ns, marks[1], 0, 3)
- set_extmark(ns, marks[2], 0, 4)
- set_extmark(ns, marks[3], 0, 5)
- set_extmark(ns, marks[4], 1, 0)
- set_extmark(ns, marks[5], 1, 5)
- set_extmark(ns, marks[6], 2, 1)
- set_extmark(ns, marks[7], 3, 0)
- feed([[:1,2s:5\n.*\n:\r<cr>]])
- check_undo_redo(ns, marks[1], 0, 3, 0, 3)
- check_undo_redo(ns, marks[2], 0, 4, 1, 0)
- check_undo_redo(ns, marks[3], 0, 5, 1, 0)
- check_undo_redo(ns, marks[4], 1, 0, 1, 0)
- check_undo_redo(ns, marks[5], 1, 5, 1, 0)
- check_undo_redo(ns, marks[6], 2, 1, 1, 1)
- check_undo_redo(ns, marks[7], 3, 0, 2, 0)
- end)
- it('substitutes with backrefs, newline inserted into sub', function()
- feed('A<cr>67890<cr>xx<cr>xx<esc>')
- set_extmark(ns, marks[1], 0, 3)
- set_extmark(ns, marks[2], 0, 4)
- set_extmark(ns, marks[3], 0, 5)
- set_extmark(ns, marks[4], 1, 0)
- set_extmark(ns, marks[5], 1, 5)
- set_extmark(ns, marks[6], 2, 0)
- feed([[:1,1s:5\(\n\):\0\1<cr>]])
- check_undo_redo(ns, marks[1], 0, 3, 0, 3)
- check_undo_redo(ns, marks[2], 0, 4, 2, 0)
- check_undo_redo(ns, marks[3], 0, 5, 2, 0)
- check_undo_redo(ns, marks[4], 1, 0, 2, 0)
- check_undo_redo(ns, marks[5], 1, 5, 2, 5)
- check_undo_redo(ns, marks[6], 2, 0, 3, 0)
- end)
- it('substitutes a ^', function()
- set_extmark(ns, marks[1], 0, 0)
- set_extmark(ns, marks[2], 0, 1)
- feed([[:s:^:x<cr>]])
- check_undo_redo(ns, marks[1], 0, 0, 0, 1)
- check_undo_redo(ns, marks[2], 0, 1, 0, 2)
- end)
- it('using <c-a> without increase in order of magnitude', function()
- -- do_addsub in ops.c
- feed('ddiabc998xxx<esc>Tc')
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 0, 3)
- set_extmark(ns, marks[3], 0, 5)
- set_extmark(ns, marks[4], 0, 6)
- set_extmark(ns, marks[5], 0, 7)
- feed('<c-a>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- check_undo_redo(ns, marks[2], 0, 3, 0, 6)
- check_undo_redo(ns, marks[3], 0, 5, 0, 6)
- check_undo_redo(ns, marks[4], 0, 6, 0, 6)
- check_undo_redo(ns, marks[5], 0, 7, 0, 7)
- end)
- it('using <c-a> when increase in order of magnitude', function()
- -- do_addsub in ops.c
- feed('ddiabc999xxx<esc>Tc')
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 0, 3)
- set_extmark(ns, marks[3], 0, 5)
- set_extmark(ns, marks[4], 0, 6)
- set_extmark(ns, marks[5], 0, 7)
- feed('<c-a>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- check_undo_redo(ns, marks[2], 0, 3, 0, 7)
- check_undo_redo(ns, marks[3], 0, 5, 0, 7)
- check_undo_redo(ns, marks[4], 0, 6, 0, 7)
- check_undo_redo(ns, marks[5], 0, 7, 0, 8)
- end)
- it('using <c-a> when negative and without decrease in order of magnitude', function()
- feed('ddiabc-999xxx<esc>T-')
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 0, 3)
- set_extmark(ns, marks[3], 0, 6)
- set_extmark(ns, marks[4], 0, 7)
- set_extmark(ns, marks[5], 0, 8)
- feed('<c-a>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- check_undo_redo(ns, marks[2], 0, 3, 0, 7)
- check_undo_redo(ns, marks[3], 0, 6, 0, 7)
- check_undo_redo(ns, marks[4], 0, 7, 0, 7)
- check_undo_redo(ns, marks[5], 0, 8, 0, 8)
- end)
- it('using <c-a> when negative and decrease in order of magnitude', function()
- feed('ddiabc-1000xxx<esc>T-')
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 0, 3)
- set_extmark(ns, marks[3], 0, 7)
- set_extmark(ns, marks[4], 0, 8)
- set_extmark(ns, marks[5], 0, 9)
- feed('<c-a>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- check_undo_redo(ns, marks[2], 0, 3, 0, 7)
- check_undo_redo(ns, marks[3], 0, 7, 0, 7)
- check_undo_redo(ns, marks[4], 0, 8, 0, 7)
- check_undo_redo(ns, marks[5], 0, 9, 0, 8)
- end)
- it('using <c-x> without decrease in order of magnitude', function()
- -- do_addsub in ops.c
- feed('ddiabc999xxx<esc>Tc')
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 0, 3)
- set_extmark(ns, marks[3], 0, 5)
- set_extmark(ns, marks[4], 0, 6)
- set_extmark(ns, marks[5], 0, 7)
- feed('<c-x>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- check_undo_redo(ns, marks[2], 0, 3, 0, 6)
- check_undo_redo(ns, marks[3], 0, 5, 0, 6)
- check_undo_redo(ns, marks[4], 0, 6, 0, 6)
- check_undo_redo(ns, marks[5], 0, 7, 0, 7)
- end)
- it('using <c-x> when decrease in order of magnitude', function()
- -- do_addsub in ops.c
- feed('ddiabc1000xxx<esc>Tc')
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 0, 3)
- set_extmark(ns, marks[3], 0, 6)
- set_extmark(ns, marks[4], 0, 7)
- set_extmark(ns, marks[5], 0, 8)
- feed('<c-x>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- check_undo_redo(ns, marks[2], 0, 3, 0, 6)
- check_undo_redo(ns, marks[3], 0, 6, 0, 6)
- check_undo_redo(ns, marks[4], 0, 7, 0, 6)
- check_undo_redo(ns, marks[5], 0, 8, 0, 7)
- end)
- it('using <c-x> when negative and without increase in order of magnitude', function()
- feed('ddiabc-998xxx<esc>T-')
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 0, 3)
- set_extmark(ns, marks[3], 0, 6)
- set_extmark(ns, marks[4], 0, 7)
- set_extmark(ns, marks[5], 0, 8)
- feed('<c-x>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- check_undo_redo(ns, marks[2], 0, 3, 0, 7)
- check_undo_redo(ns, marks[3], 0, 6, 0, 7)
- check_undo_redo(ns, marks[4], 0, 7, 0, 7)
- check_undo_redo(ns, marks[5], 0, 8, 0, 8)
- end)
- it('using <c-x> when negative and increase in order of magnitude', function()
- feed('ddiabc-999xxx<esc>T-')
- set_extmark(ns, marks[1], 0, 2)
- set_extmark(ns, marks[2], 0, 3)
- set_extmark(ns, marks[3], 0, 6)
- set_extmark(ns, marks[4], 0, 7)
- set_extmark(ns, marks[5], 0, 8)
- feed('<c-x>')
- check_undo_redo(ns, marks[1], 0, 2, 0, 2)
- check_undo_redo(ns, marks[2], 0, 3, 0, 8)
- check_undo_redo(ns, marks[3], 0, 6, 0, 8)
- check_undo_redo(ns, marks[4], 0, 7, 0, 8)
- check_undo_redo(ns, marks[5], 0, 8, 0, 9)
- end)
- it('throws consistent error codes', function()
- local ns_invalid = ns2 + 1
- eq(
- "Invalid 'ns_id': 3",
- pcall_err(set_extmark, ns_invalid, marks[1], positions[1][1], positions[1][2])
- )
- eq("Invalid 'ns_id': 3", pcall_err(api.nvim_buf_del_extmark, 0, ns_invalid, marks[1]))
- eq("Invalid 'ns_id': 3", pcall_err(get_extmarks, ns_invalid, positions[1], positions[2]))
- eq("Invalid 'ns_id': 3", pcall_err(get_extmark_by_id, ns_invalid, marks[1]))
- end)
- it('when col = line-length, set the mark on eol', function()
- set_extmark(ns, marks[1], 0, -1)
- local rv = get_extmark_by_id(ns, marks[1])
- eq({ 0, init_text:len() }, rv)
- -- Test another
- set_extmark(ns, marks[1], 0, -1)
- rv = get_extmark_by_id(ns, marks[1])
- eq({ 0, init_text:len() }, rv)
- end)
- it('when col = line-length, set the mark on eol', function()
- local invalid_col = init_text:len() + 1
- eq("Invalid 'col': out of range", pcall_err(set_extmark, ns, marks[1], 0, invalid_col))
- end)
- it('fails when line > line_count', function()
- local invalid_col = init_text:len() + 1
- local invalid_lnum = 3
- eq(
- "Invalid 'line': out of range",
- pcall_err(set_extmark, ns, marks[1], invalid_lnum, invalid_col)
- )
- eq({}, get_extmark_by_id(ns, marks[1]))
- end)
- it('bug from check_col in extmark_set', function()
- -- This bug was caused by extmark_set always using check_col. check_col
- -- always uses the current buffer. This wasn't working during undo so we
- -- now use check_col and check_lnum only when they are required.
- feed('A<cr>67890<cr>xx<esc>')
- feed('A<cr>12345<cr>67890<cr>xx<esc>')
- set_extmark(ns, marks[1], 3, 4)
- feed([[:1,5s:5\n:5 <cr>]])
- check_undo_redo(ns, marks[1], 3, 4, 2, 6)
- end)
- it('in read-only buffer', function()
- command('view! runtime/doc/help.txt')
- eq(true, api.nvim_get_option_value('ro', {}))
- local id = set_extmark(ns, 0, 0, 2)
- eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1))
- end)
- it('can set a mark to other buffer', function()
- local buf = request('nvim_create_buf', 0, 1)
- request('nvim_buf_set_lines', buf, 0, -1, 1, { '', '' })
- local id = api.nvim_buf_set_extmark(buf, ns, 1, 0, {})
- eq({ { id, 1, 0 } }, api.nvim_buf_get_extmarks(buf, ns, 0, -1, {}))
- end)
- it('does not crash with append/delete/undo sequence', function()
- exec([[
- let ns = nvim_create_namespace('myplugin')
- call nvim_buf_set_extmark(0, ns, 0, 0, {})
- call append(0, '')
- %delete
- undo]])
- assert_alive()
- end)
- it('works with left and right gravity', function()
- -- right gravity should move with inserted text, while
- -- left gravity should stay in place.
- api.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = false })
- api.nvim_buf_set_extmark(0, ns, 0, 5, { right_gravity = true })
- feed([[Aasdfasdf]])
- eq({ { 1, 0, 5 }, { 2, 0, 13 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
- -- but both move when text is inserted before
- feed([[<esc>Iasdf<esc>]])
- -- eq({}, api.nvim_buf_get_lines(0, 0, -1, true))
- eq({ { 1, 0, 9 }, { 2, 0, 17 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
- -- clear text
- api.nvim_buf_set_text(0, 0, 0, 0, 17, {})
- -- handles set_text correctly as well
- eq({ { 1, 0, 0 }, { 2, 0, 0 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
- api.nvim_buf_set_text(0, 0, 0, 0, 0, { 'asdfasdf' })
- eq({ { 1, 0, 0 }, { 2, 0, 8 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
- feed('u')
- -- handles pasting
- exec([[let @a='asdfasdf']])
- feed([["ap]])
- eq({ { 1, 0, 0 }, { 2, 0, 8 } }, api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
- end)
- it('can accept "end_row" or "end_line" #16548', function()
- set_extmark(ns, marks[1], 0, 0, {
- end_col = 0,
- end_line = 1,
- })
- eq({
- {
- 1,
- 0,
- 0,
- {
- ns_id = 1,
- end_col = 0,
- end_row = 1,
- right_gravity = true,
- end_right_gravity = false,
- },
- },
- }, get_extmarks(ns, 0, -1, { details = true }))
- end)
- it('in prompt buffer', function()
- feed('dd')
- local id = set_extmark(ns, marks[1], 0, 0, {})
- api.nvim_set_option_value('buftype', 'prompt', {})
- feed('i<esc>')
- eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1))
- end)
- it('can get details', function()
- set_extmark(ns, marks[1], 0, 0, {
- conceal = 'c',
- cursorline_hl_group = 'Statement',
- end_col = 0,
- end_right_gravity = true,
- end_row = 1,
- hl_eol = true,
- hl_group = 'String',
- hl_mode = 'blend',
- line_hl_group = 'Statement',
- number_hl_group = 'Statement',
- priority = 0,
- right_gravity = false,
- sign_hl_group = 'Statement',
- sign_text = '>>',
- spell = true,
- virt_lines = {
- { { 'lines', 'Macro' }, { '???' }, { ';;;', '' } },
- { { 'stack', { 'Type', 'Search' } }, { '!!!' } },
- },
- virt_lines_above = true,
- virt_lines_leftcol = true,
- virt_text = { { 'text', 'Macro' }, { '???' }, { 'stack', { 'Type', 'Search' } } },
- virt_text_hide = true,
- virt_text_pos = 'right_align',
- })
- set_extmark(ns, marks[2], 0, 0, {
- priority = 0,
- virt_text = { { '', 'Macro' }, { '', { 'Type', 'Search' } }, { '' } },
- virt_text_win_col = 1,
- })
- eq({
- 0,
- 0,
- {
- conceal = 'c',
- cursorline_hl_group = 'Statement',
- end_col = 0,
- end_right_gravity = true,
- end_row = 1,
- hl_eol = true,
- hl_group = 'String',
- hl_mode = 'blend',
- line_hl_group = 'Statement',
- ns_id = 1,
- number_hl_group = 'Statement',
- priority = 0,
- right_gravity = false,
- sign_hl_group = 'Statement',
- sign_text = '>>',
- spell = true,
- virt_lines = {
- { { 'lines', 'Macro' }, { '???' }, { ';;;', '' } },
- { { 'stack', { 'Type', 'Search' } }, { '!!!' } },
- },
- virt_lines_above = true,
- virt_lines_leftcol = true,
- virt_text = { { 'text', 'Macro' }, { '???' }, { 'stack', { 'Type', 'Search' } } },
- virt_text_repeat_linebreak = false,
- virt_text_hide = true,
- virt_text_pos = 'right_align',
- },
- }, get_extmark_by_id(ns, marks[1], { details = true }))
- eq({
- 0,
- 0,
- {
- ns_id = 1,
- right_gravity = true,
- priority = 0,
- virt_text = { { '', 'Macro' }, { '', { 'Type', 'Search' } }, { '' } },
- virt_text_repeat_linebreak = false,
- virt_text_hide = false,
- virt_text_pos = 'win_col',
- virt_text_win_col = 1,
- },
- }, get_extmark_by_id(ns, marks[2], { details = true }))
- set_extmark(ns, marks[3], 0, 0, { cursorline_hl_group = 'Statement' })
- eq({
- 0,
- 0,
- {
- ns_id = 1,
- cursorline_hl_group = 'Statement',
- priority = 4096,
- right_gravity = true,
- },
- }, get_extmark_by_id(ns, marks[3], { details = true }))
- set_extmark(ns, marks[4], 0, 0, {
- end_col = 1,
- conceal = 'a',
- spell = true,
- })
- eq({
- 0,
- 0,
- {
- conceal = 'a',
- end_col = 1,
- end_right_gravity = false,
- end_row = 0,
- ns_id = 1,
- right_gravity = true,
- spell = true,
- },
- }, get_extmark_by_id(ns, marks[4], { details = true }))
- set_extmark(ns, marks[5], 0, 0, {
- end_col = 1,
- spell = false,
- })
- eq({
- 0,
- 0,
- {
- end_col = 1,
- end_right_gravity = false,
- end_row = 0,
- ns_id = 1,
- right_gravity = true,
- spell = false,
- },
- }, get_extmark_by_id(ns, marks[5], { details = true }))
- api.nvim_buf_clear_namespace(0, ns, 0, -1)
- -- legacy sign mark includes sign name
- command('sign define sign1 text=s1 texthl=Title linehl=LineNR numhl=Normal culhl=CursorLine')
- command('sign place 1 name=sign1 line=1')
- eq({
- {
- 1,
- 0,
- 0,
- {
- cursorline_hl_group = 'CursorLine',
- invalidate = true,
- line_hl_group = 'LineNr',
- ns_id = 0,
- number_hl_group = 'Normal',
- priority = 10,
- right_gravity = true,
- sign_hl_group = 'Title',
- sign_name = 'sign1',
- sign_text = 's1',
- undo_restore = false,
- },
- },
- }, get_extmarks(-1, 0, -1, { details = true }))
- end)
- it('can get marks from anonymous namespaces', function()
- ns = request('nvim_create_namespace', '')
- ns2 = request('nvim_create_namespace', '')
- set_extmark(ns, 1, 0, 0, {})
- set_extmark(ns2, 2, 1, 0, {})
- eq({
- { 1, 0, 0, { ns_id = ns, right_gravity = true } },
- { 2, 1, 0, { ns_id = ns2, right_gravity = true } },
- }, get_extmarks(-1, 0, -1, { details = true }))
- end)
- it('can filter by extmark properties', function()
- set_extmark(ns, 1, 0, 0, {})
- set_extmark(ns, 2, 0, 0, { hl_group = 'Normal' })
- set_extmark(ns, 3, 0, 0, { sign_text = '>>' })
- set_extmark(ns, 4, 0, 0, { virt_text = { { 'text', 'Normal' } } })
- set_extmark(ns, 5, 0, 0, { virt_lines = { { { 'line', 'Normal' } } } })
- eq(5, #get_extmarks(-1, 0, -1, {}))
- eq({ { 2, 0, 0 } }, get_extmarks(-1, 0, -1, { type = 'highlight' }))
- eq({ { 3, 0, 0 } }, get_extmarks(-1, 0, -1, { type = 'sign' }))
- eq({ { 4, 0, 0 } }, get_extmarks(-1, 0, -1, { type = 'virt_text' }))
- eq({ { 5, 0, 0 } }, get_extmarks(-1, 0, -1, { type = 'virt_lines' }))
- end)
- it('invalidated marks are deleted', function()
- screen = Screen.new(40, 6)
- feed('dd6iaaa bbb ccc<CR><ESC>gg')
- api.nvim_set_option_value('signcolumn', 'auto:2', {})
- set_extmark(ns, 1, 0, 0, { invalidate = true, sign_text = 'S1', end_row = 1 })
- set_extmark(ns, 2, 1, 0, { invalidate = true, sign_text = 'S2', end_row = 2 })
- -- mark with invalidate is removed
- command('d2')
- screen:expect([[
- {7:S2}^aaa bbb ccc |
- {7: }aaa bbb ccc |*3
- {7: } |
- |
- ]])
- -- mark is restored with undo_restore == true
- command('silent undo')
- screen:expect([[
- {7:S1 }^aaa bbb ccc |
- {7:S2S1}aaa bbb ccc |
- {7:S2 }aaa bbb ccc |
- {7: }aaa bbb ccc |*2
- |
- ]])
- -- decor is not removed twice
- command('d3')
- api.nvim_buf_del_extmark(0, ns, 1)
- command('silent undo')
- -- mark is deleted with undo_restore == false
- set_extmark(ns, 1, 0, 0, { invalidate = true, undo_restore = false, sign_text = 'S1' })
- set_extmark(ns, 2, 1, 0, { invalidate = true, undo_restore = false, sign_text = 'S2' })
- command('1d 2')
- eq(0, #get_extmarks(-1, 0, -1, {}))
- -- mark is not removed when deleting bytes before the range
- set_extmark(ns, 3, 0, 4, {
- invalidate = true,
- undo_restore = true,
- hl_group = 'Error',
- end_col = 7,
- right_gravity = false,
- })
- feed('dw')
- eq(3, get_extmark_by_id(ns, 3, { details = true })[3].end_col)
- -- mark is not removed when deleting bytes at the start of the range
- feed('x')
- eq(2, get_extmark_by_id(ns, 3, { details = true })[3].end_col)
- -- mark is not removed when deleting bytes from the end of the range
- feed('lx')
- eq(1, get_extmark_by_id(ns, 3, { details = true })[3].end_col)
- -- mark is not removed when deleting bytes beyond end of the range
- feed('x')
- eq(1, get_extmark_by_id(ns, 3, { details = true })[3].end_col)
- -- mark is removed when all bytes in the range are deleted
- feed('hx')
- eq(true, get_extmark_by_id(ns, 3, { details = true })[3].invalid)
- -- mark is restored with undo_restore == true if pos did not change
- command('undo')
- eq(nil, get_extmark_by_id(ns, 3, { details = true })[3].invalid)
- -- multiline mark is not removed when start of its range is deleted
- set_extmark(ns, 4, 1, 4, {
- undo_restore = false,
- invalidate = true,
- hl_group = 'Error',
- end_col = 7,
- end_row = 3,
- })
- feed('ddDdd')
- eq({ 0, 0 }, get_extmark_by_id(ns, 4, {}))
- -- multiline mark is removed when entirety of its range is deleted
- feed('vj2ed')
- eq({}, get_extmark_by_id(ns, 4, {}))
- end)
- it('no crash checking invalidated flag of sign pair end key #31856', function()
- api.nvim_buf_set_lines(0, 0, 1, false, { '', '' })
- api.nvim_set_option_value('signcolumn', 'auto:2', {})
- set_extmark(ns, 1, 0, 0, { sign_text = 'S1', invalidate = true, end_row = 0 })
- set_extmark(ns, 2, 1, 0, { sign_text = 'S2', end_row = 1 })
- command('d')
- api.nvim_buf_clear_namespace(0, ns, 0, -1)
- n.assert_alive()
- end)
- it('can set a URL', function()
- local url1 = 'https://example.com'
- local url2 = 'http://127.0.0.1'
- set_extmark(ns, 1, 0, 0, { url = url1, end_col = 3 })
- set_extmark(ns, 2, 0, 3, { url = url2, hl_group = 'Search', end_col = 5 })
- local extmarks = get_extmarks(ns, 0, -1, { details = true })
- eq(2, #extmarks)
- eq(url1, extmarks[1][4].url)
- eq(url2, extmarks[2][4].url)
- eq('Search', extmarks[2][4].hl_group)
- end)
- it('respects priority', function()
- screen = Screen.new(15, 10)
- set_extmark(ns, marks[1], 0, 0, {
- hl_group = 'Comment',
- end_col = 2,
- priority = 20,
- })
- -- Extmark defined after first extmark but has lower priority, first extmark "wins"
- set_extmark(ns, marks[2], 0, 0, {
- hl_group = 'String',
- end_col = 2,
- priority = 10,
- })
- screen:expect {
- grid = [[
- {1:12}34^5 |
- {2:~ }|*8
- |
- ]],
- attr_ids = {
- [1] = { foreground = Screen.colors.Blue1 },
- [2] = { foreground = Screen.colors.Blue1, bold = true },
- },
- }
- end)
- end)
- describe('Extmarks buffer api with many marks', function()
- local ns1
- local ns2
- local ns_marks = {}
- before_each(function()
- clear()
- ns1 = request('nvim_create_namespace', 'ns1')
- ns2 = request('nvim_create_namespace', 'ns2')
- ns_marks = { [ns1] = {}, [ns2] = {} }
- local lines = {}
- for i = 1, 30 do
- lines[#lines + 1] = string.rep('x ', i)
- end
- api.nvim_buf_set_lines(0, 0, -1, true, lines)
- local ns = ns1
- local q = 0
- for i = 0, 29 do
- for j = 0, i do
- local id = set_extmark(ns, 0, i, j)
- eq(nil, ns_marks[ns][id])
- ok(id > 0)
- ns_marks[ns][id] = { i, j }
- ns = ns1 + ns2 - ns
- q = q + 1
- end
- end
- eq(233, #ns_marks[ns1])
- eq(232, #ns_marks[ns2])
- end)
- local function get_marks(ns)
- local mark_list = get_extmarks(ns, 0, -1)
- local marks = {}
- for _, mark in ipairs(mark_list) do
- local id, row, col = unpack(mark)
- eq(nil, marks[id], 'duplicate mark')
- marks[id] = { row, col }
- end
- return marks
- end
- it('can get marks', function()
- eq(ns_marks[ns1], get_marks(ns1))
- eq(ns_marks[ns2], get_marks(ns2))
- end)
- it('can clear all marks in ns', function()
- api.nvim_buf_clear_namespace(0, ns1, 0, -1)
- eq({}, get_marks(ns1))
- eq(ns_marks[ns2], get_marks(ns2))
- api.nvim_buf_clear_namespace(0, ns2, 0, -1)
- eq({}, get_marks(ns1))
- eq({}, get_marks(ns2))
- end)
- it('can clear line range', function()
- api.nvim_buf_clear_namespace(0, ns1, 10, 20)
- for id, mark in pairs(ns_marks[ns1]) do
- if 10 <= mark[1] and mark[1] < 20 then
- ns_marks[ns1][id] = nil
- end
- end
- eq(ns_marks[ns1], get_marks(ns1))
- eq(ns_marks[ns2], get_marks(ns2))
- api.nvim_buf_clear_namespace(0, ns1, 0, 10)
- for id, mark in pairs(ns_marks[ns1]) do
- if mark[1] < 10 then
- ns_marks[ns1][id] = nil
- end
- end
- eq(ns_marks[ns1], get_marks(ns1))
- eq(ns_marks[ns2], get_marks(ns2))
- api.nvim_buf_clear_namespace(0, ns1, 20, -1)
- for id, mark in pairs(ns_marks[ns1]) do
- if mark[1] >= 20 then
- ns_marks[ns1][id] = nil
- end
- end
- eq(ns_marks[ns1], get_marks(ns1))
- eq(ns_marks[ns2], get_marks(ns2))
- end)
- it('can delete line', function()
- feed('10Gdd')
- for _, marks in pairs(ns_marks) do
- for id, mark in pairs(marks) do
- if mark[1] == 9 then
- marks[id] = { 9, 0 }
- elseif mark[1] >= 10 then
- mark[1] = mark[1] - 1
- end
- end
- end
- eq(ns_marks[ns1], get_marks(ns1))
- eq(ns_marks[ns2], get_marks(ns2))
- end)
- it('can delete lines', function()
- feed('10G10dd')
- for _, marks in pairs(ns_marks) do
- for id, mark in pairs(marks) do
- if 9 <= mark[1] and mark[1] < 19 then
- marks[id] = { 9, 0 }
- elseif mark[1] >= 19 then
- mark[1] = mark[1] - 10
- end
- end
- end
- eq(ns_marks[ns1], get_marks(ns1))
- eq(ns_marks[ns2], get_marks(ns2))
- end)
- it('can wipe buffer', function()
- command('bwipe!')
- eq({}, get_marks(ns1))
- eq({}, get_marks(ns2))
- end)
- end)
- describe('API/win_extmark', function()
- local screen
- local marks, line1, line2
- local ns
- before_each(function()
- -- Initialize some namespaces and insert text into a buffer
- marks = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
- line1 = 'non ui-watched line'
- line2 = 'ui-watched line'
- clear()
- insert(line1)
- feed('o<esc>')
- insert(line2)
- ns = request('nvim_create_namespace', 'extmark-ui')
- end)
- it('sends and only sends ui-watched marks to ui', function()
- screen = Screen.new(20, 4)
- -- should send this
- set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
- -- should not send this
- set_extmark(ns, marks[2], 0, 0, { ui_watched = false })
- screen:expect({
- grid = [[
- non ui-watched line |
- ui-watched lin^e |
- {1:~ }|
- |
- ]],
- extmarks = {
- [2] = {
- -- positioned at the end of the 2nd line
- { 1000, ns, marks[1], 1, 16 },
- },
- },
- })
- end)
- it('sends multiple ui-watched marks to ui', function()
- screen = Screen.new(20, 4)
- feed('15A!<Esc>')
- -- should send all of these
- set_extmark(ns, marks[1], 1, 0, { ui_watched = true, virt_text_pos = 'overlay' })
- set_extmark(ns, marks[2], 1, 2, { ui_watched = true, virt_text_pos = 'overlay' })
- set_extmark(ns, marks[3], 1, 4, { ui_watched = true, virt_text_pos = 'overlay' })
- set_extmark(ns, marks[4], 1, 6, { ui_watched = true, virt_text_pos = 'overlay' })
- set_extmark(ns, marks[5], 1, 8, { ui_watched = true })
- screen:expect({
- grid = [[
- non ui-watched line |
- ui-watched line!!!!!|
- !!!!!!!!!^! |
- |
- ]],
- extmarks = {
- [2] = {
- -- notification from 1st call
- { 1000, ns, marks[1], 1, 0 },
- -- notifications from 2nd call
- { 1000, ns, marks[1], 1, 0 },
- { 1000, ns, marks[2], 1, 2 },
- -- notifications from 3rd call
- { 1000, ns, marks[1], 1, 0 },
- { 1000, ns, marks[2], 1, 2 },
- { 1000, ns, marks[3], 1, 4 },
- -- notifications from 4th call
- { 1000, ns, marks[1], 1, 0 },
- { 1000, ns, marks[2], 1, 2 },
- { 1000, ns, marks[3], 1, 4 },
- { 1000, ns, marks[4], 1, 6 },
- -- final
- -- overlay
- { 1000, ns, marks[1], 1, 0 },
- { 1000, ns, marks[2], 1, 2 },
- { 1000, ns, marks[3], 1, 4 },
- { 1000, ns, marks[4], 1, 6 },
- -- eol
- { 1000, ns, marks[5], 2, 11 },
- },
- },
- })
- end)
- it('updates ui-watched marks', function()
- screen = Screen.new(20, 4)
- -- should send this
- set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
- -- should not send this
- set_extmark(ns, marks[2], 0, 0, { ui_watched = false })
- -- make some changes
- insert(' update')
- screen:expect({
- grid = [[
- non ui-watched line |
- ui-watched linupdat^e|
- e |
- |
- ]],
- extmarks = {
- [2] = {
- -- positioned at the end of the 2nd line
- { 1000, ns, marks[1], 1, 16 },
- -- updated and wrapped to 3rd line
- { 1000, ns, marks[1], 2, 2 },
- },
- },
- })
- feed('<c-e>')
- screen:expect({
- grid = [[
- ui-watched linupdat^e|
- e |
- {1:~ }|
- |
- ]],
- extmarks = {
- [2] = {
- -- positioned at the end of the 2nd line
- { 1000, ns, marks[1], 1, 16 },
- -- updated and wrapped to 3rd line
- { 1000, ns, marks[1], 2, 2 },
- -- scrolled up one line, should be handled by grid scroll
- },
- },
- })
- end)
- it('sends ui-watched to splits', function()
- screen = Screen.new(20, 8, { ext_multigrid = true })
- -- should send this
- set_extmark(ns, marks[1], 1, 0, { ui_watched = true })
- -- should not send this
- set_extmark(ns, marks[2], 0, 0, { ui_watched = false })
- command('split')
- screen:expect({
- grid = [[
- ## grid 1
- [4:--------------------]|*3
- {3:[No Name] [+] }|
- [2:--------------------]|*2
- {2:[No Name] [+] }|
- [3:--------------------]|
- ## grid 2
- non ui-watched line |
- ui-watched line |
- ## grid 3
- |
- ## grid 4
- non ui-watched line |
- ui-watched lin^e |
- {1:~ }|
- ]],
- extmarks = {
- [2] = {
- -- positioned at the end of the 2nd line
- { 1000, ns, marks[1], 1, 16 },
- -- updated after split
- { 1000, ns, marks[1], 1, 16 },
- },
- [4] = {
- -- only after split
- { 1001, ns, marks[1], 1, 16 },
- },
- },
- })
- -- make some changes
- insert(' update')
- screen:expect({
- grid = [[
- ## grid 1
- [4:--------------------]|*3
- {3:[No Name] [+] }|
- [2:--------------------]|*2
- {2:[No Name] [+] }|
- [3:--------------------]|
- ## grid 2
- non ui-watched line |
- ui-watched linupd{1:@@@}|
- ## grid 3
- |
- ## grid 4
- non ui-watched line |
- ui-watched linupdat^e|
- e |
- ]],
- extmarks = {
- [2] = {
- -- positioned at the end of the 2nd line
- { 1000, ns, marks[1], 1, 16 },
- -- updated after split
- { 1000, ns, marks[1], 1, 16 },
- },
- [4] = {
- { 1001, ns, marks[1], 1, 16 },
- -- updated
- { 1001, ns, marks[1], 2, 2 },
- },
- },
- })
- end)
- end)
|