mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
api: set_text: rebase, update to new api, and add more tests
This commit is contained in:
@@ -409,6 +409,14 @@ describe('api/buf', function()
|
||||
set_text(0, 6, 0, 9, {'world'})
|
||||
eq({'hello world!', 'text'}, get_lines(0, 2, true))
|
||||
|
||||
-- can insert text
|
||||
set_text(0, 0, 0, 0, {'well '})
|
||||
eq({'well hello world!', 'text'}, get_lines(0, 2, true))
|
||||
|
||||
-- can delete text
|
||||
set_text(0, 0, 0, 5, {''})
|
||||
eq({'hello world!', 'text'}, get_lines(0, 2, true))
|
||||
|
||||
-- can replace with multiple lines
|
||||
local err = set_text(0, 6, 0, 11, {'foo', 'wo', 'more'})
|
||||
eq({'hello foo', 'wo', 'more!', 'text'}, get_lines(0, 4, true))
|
||||
@@ -418,6 +426,43 @@ describe('api/buf', function()
|
||||
eq({'hello bar'}, get_lines(0, 1, true))
|
||||
end)
|
||||
|
||||
pending('can handle multibyte characters', function()
|
||||
insert([[
|
||||
hellØ world!
|
||||
]])
|
||||
|
||||
eq({'hellØ world!'}, get_lines(0, 1, true))
|
||||
|
||||
-- inserting multibyte
|
||||
set_text(0, 11, 0, 11, {'Ø'})
|
||||
eq({'hellØ worldØ!'}, get_lines(0, 1, true))
|
||||
|
||||
-- deleting multibyte
|
||||
set_text(0, 0, 0, 6, {''})
|
||||
eq({'worldØ!'}, get_lines(0, 1, true))
|
||||
end)
|
||||
|
||||
it('works with undo', function()
|
||||
insert([[
|
||||
hello world!
|
||||
]])
|
||||
|
||||
-- setting text
|
||||
set_text(0, 0, 0, 0, {'well '})
|
||||
feed('u')
|
||||
eq({'hello world!'}, get_lines(0, 1, true))
|
||||
|
||||
-- deleting text
|
||||
set_text(0, 0, 0, 6, {''})
|
||||
feed('u')
|
||||
eq({'hello world!'}, get_lines(0, 1, true))
|
||||
|
||||
-- inserting newlines
|
||||
set_text(0, 0, 0, 0, {'hello', 'mr '})
|
||||
feed('u')
|
||||
eq({'hello world!'}, get_lines(0, 1, true))
|
||||
end)
|
||||
|
||||
it('updates the cursor position', function()
|
||||
insert([[
|
||||
hello world!
|
||||
@@ -443,34 +488,34 @@ describe('api/buf', function()
|
||||
foo bar
|
||||
baz
|
||||
]])
|
||||
local id1 = curbufmeths.set_extmark(ns, 0, 0, 1, {})
|
||||
local id2 = curbufmeths.set_extmark(ns, 0, 0, 7, {})
|
||||
local id3 = curbufmeths.set_extmark(ns, 0, 1, 1, {})
|
||||
local id1 = curbufmeths.set_extmark(ns, 0, 1, {})
|
||||
local id2 = curbufmeths.set_extmark(ns, 0, 7, {})
|
||||
local id3 = curbufmeths.set_extmark(ns, 1, 1, {})
|
||||
set_text(0, 4, 0, 7, {"q"})
|
||||
|
||||
-- TODO: if we set text at 0,3, what happens to the mark at 0,3
|
||||
|
||||
eq({'foo q', 'baz'}, get_lines(0, 2, true))
|
||||
-- mark before replacement point is unaffected
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id1)
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id1, {})
|
||||
eq({0, 1}, rv)
|
||||
-- mark gets shifted back because the replacement was shorter
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id2)
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id2, {})
|
||||
eq({0, 5}, rv)
|
||||
-- mark on the next line is unaffected
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id3)
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id3, {})
|
||||
eq({1, 1}, rv)
|
||||
|
||||
-- replacing the text spanning two lines will adjust the mark on the next line
|
||||
set_text(0, 3, 1, 3, {"qux"})
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id3)
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id3, {})
|
||||
eq({'fooqux', ''}, get_lines(0, 2, true))
|
||||
eq({0, 6}, rv)
|
||||
-- but mark before replacement point is still unaffected
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id1)
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id1, {})
|
||||
eq({0, 1}, rv)
|
||||
-- and the mark in the middle was shifted to the end of the insertion
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id2)
|
||||
rv = curbufmeths.get_extmark_by_id(ns, id2, {})
|
||||
eq({0, 6}, rv)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user