Merge pull request #12911 from vigoux/bytetrack-formatoption-ro

treesitter: filter updates on <CR>
This commit is contained in:
Björn Linse 2020-09-16 19:53:39 +02:00 committed by GitHub
commit d4b4335fe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 10 deletions

View File

@ -1676,9 +1676,16 @@ int open_line(
truncate_spaces(saved_line);
}
ml_replace(curwin->w_cursor.lnum, saved_line, false);
extmark_splice_cols(
curbuf, (int)curwin->w_cursor.lnum,
0, curwin->w_cursor.col, (int)STRLEN(saved_line), kExtmarkUndo);
int new_len = (int)STRLEN(saved_line);
// TODO(vigoux): maybe there is issues there with expandtabs ?
if (new_len < curwin->w_cursor.col) {
extmark_splice_cols(
curbuf, (int)curwin->w_cursor.lnum,
new_len, curwin->w_cursor.col - new_len, 0, kExtmarkUndo);
}
saved_line = NULL;
if (did_append) {
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,

View File

@ -257,9 +257,9 @@ describe('lua: nvim_buf_attach on_bytes', function()
-- assert the wrong thing), but masks errors with unflushed lines (as
-- nvim_buf_get_offset forces a flush of the memline). To be safe run the
-- test both ways.
local function setup_eventcheck(verify)
meths.buf_set_lines(0, 0, -1, true, origlines)
local shadow = deepcopy(origlines)
local function setup_eventcheck(verify, start_txt)
meths.buf_set_lines(0, 0, -1, true, start_txt)
local shadow = deepcopy(start_txt)
local shadowbytes = table.concat(shadow, '\n') .. '\n'
-- TODO: while we are brewing the real strong coffe,
-- verify should check buf_get_offset after every check_events
@ -317,7 +317,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
-- Yes, we can do both
local function do_both(verify)
it('single and multiple join', function()
local check_events = setup_eventcheck(verify)
local check_events = setup_eventcheck(verify, origlines)
feed 'ggJ'
check_events {
{'test1', 'bytes', 1, 3, 0, 15, 15, 1, 0, 1, 0, 1, 1};
@ -331,7 +331,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
end)
it('opening lines', function()
local check_events = setup_eventcheck(verify)
local check_events = setup_eventcheck(verify, origlines)
-- meths.buf_set_option(0, 'autoindent', true)
feed 'Go'
check_events {
@ -344,7 +344,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
end)
it('opening lines with autoindent', function()
local check_events = setup_eventcheck(verify)
local check_events = setup_eventcheck(verify, origlines)
meths.buf_set_option(0, 'autoindent', true)
feed 'Go'
check_events {
@ -358,7 +358,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
end)
it('setline(num, line)', function()
local check_events = setup_eventcheck(verify)
local check_events = setup_eventcheck(verify, origlines)
funcs.setline(2, "babla")
check_events {
{ "test1", "bytes", 1, 3, 1, 0, 16, 0, 15, 15, 0, 5, 5 };
@ -376,6 +376,32 @@ describe('lua: nvim_buf_attach on_bytes', function()
{ "test1", "bytes", 1, 6, 7, 0, 90, 0, 0, 0, 1, 0, 4 };
}
end)
it('continuing comments with fo=or', function()
local check_events = setup_eventcheck(verify, {'// Comment'})
meths.buf_set_option(0, 'formatoptions', 'ro')
meths.buf_set_option(0, 'filetype', 'c')
feed 'A<CR>'
check_events {
{ "test1", "bytes", 1, 4, 0, 10, 10, 0, 0, 0, 1, 3, 4 };
}
feed '<ESC>'
check_events {
{ "test1", "bytes", 1, 4, 1, 2, 13, 0, 1, 1, 0, 0, 0 };
}
feed 'ggo' -- goto first line to continue testing
check_events {
{ "test1", "bytes", 1, 6, 1, 0, 11, 0, 0, 0, 1, 0, 4 };
}
feed '<CR>'
check_events {
{ "test1", "bytes", 1, 6, 2, 2, 16, 0, 1, 1, 0, 0, 0 };
{ "test1", "bytes", 1, 7, 1, 3, 14, 0, 0, 0, 1, 3, 4 };
}
end)
end
describe('(with verify) handles', function()