aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2020-09-16 19:53:39 +0200
committerGitHub <noreply@github.com>2020-09-16 19:53:39 +0200
commitd4b4335fe330bf0558d38883cb8a2b47e8ece28a (patch)
treed7c518b675dff43ccf153a71d8c435bdef797a4f
parentaa98527ce7efc1b4fd38e1d17c6f455239f39f21 (diff)
parent9a7f111db67c4592ff9794e778b0ff60d0157afe (diff)
downloadrneovim-d4b4335fe330bf0558d38883cb8a2b47e8ece28a.tar.gz
rneovim-d4b4335fe330bf0558d38883cb8a2b47e8ece28a.tar.bz2
rneovim-d4b4335fe330bf0558d38883cb8a2b47e8ece28a.zip
Merge pull request #12911 from vigoux/bytetrack-formatoption-ro
treesitter: filter updates on <CR>
-rw-r--r--src/nvim/change.c13
-rw-r--r--test/functional/lua/buffer_updates_spec.lua40
2 files changed, 43 insertions, 10 deletions
diff --git a/src/nvim/change.c b/src/nvim/change.c
index 8bf02385ef..71614363d2 100644
--- a/src/nvim/change.c
+++ b/src/nvim/change.c
@@ -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,
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index cc5db2a355..faf63e7374 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -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()