diff options
-rw-r--r-- | src/nvim/api/options.c | 6 | ||||
-rw-r--r-- | src/nvim/eval.c | 15 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 41 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 5 | ||||
-rw-r--r-- | src/nvim/getchar.c | 3 | ||||
-rw-r--r-- | src/nvim/indent.c | 6 | ||||
-rw-r--r-- | src/nvim/syntax.c | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_cmdline.vim | 8 | ||||
-rw-r--r-- | src/nvim/testdir/test_lispwords.vim | 12 | ||||
-rw-r--r-- | src/nvim/testdir/test_syntax.vim | 88 | ||||
-rw-r--r-- | src/nvim/ui.c | 5 | ||||
-rw-r--r-- | src/nvim/ui_compositor.c | 13 | ||||
-rw-r--r-- | test/functional/ex_cmds/map_spec.lua | 22 | ||||
-rw-r--r-- | test/functional/fixtures/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/vimscript/screenchar_spec.lua | 69 |
16 files changed, 260 insertions, 41 deletions
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c index 3067a6e6b4..19ce25f676 100644 --- a/src/nvim/api/options.c +++ b/src/nvim/api/options.c @@ -43,6 +43,9 @@ static int validate_option_value_args(Dict(option) *opts, int *scope, int *opt_t if (opts->win.type == kObjectTypeInteger) { *opt_type = SREQ_WIN; *from = find_window_by_handle((int)opts->win.data.integer, err); + if (ERROR_SET(err)) { + return FAIL; + } } else if (HAS_KEY(opts->win)) { api_set_error(err, kErrorTypeValidation, "invalid value for key: win"); return FAIL; @@ -52,6 +55,9 @@ static int validate_option_value_args(Dict(option) *opts, int *scope, int *opt_t *scope = OPT_LOCAL; *opt_type = SREQ_BUF; *from = find_buffer_by_handle((int)opts->buf.data.integer, err); + if (ERROR_SET(err)) { + return FAIL; + } } else if (HAS_KEY(opts->buf)) { api_set_error(err, kErrorTypeValidation, "invalid value for key: buf"); return FAIL; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index a4f56b47e6..43d6ed558f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -49,6 +49,7 @@ #include "nvim/sign.h" #include "nvim/syntax.h" #include "nvim/ui.h" +#include "nvim/ui_compositor.h" #include "nvim/undo.h" #include "nvim/version.h" #include "nvim/window.h" @@ -6849,19 +6850,19 @@ void return_register(int regname, typval_T *rettv) rettv->vval.v_string = xstrdup(buf); } -void screenchar_adjust_grid(ScreenGrid **grid, int *row, int *col) +void screenchar_adjust(ScreenGrid **grid, int *row, int *col) { // TODO(bfredl): this is a hack for legacy tests which use screenchar() // to check printed messages on the screen (but not floats etc // as these are not legacy features). If the compositor is refactored to // have its own buffer, this should just read from it instead. msg_scroll_flush(); - if (msg_grid.chars && msg_grid.comp_index > 0 && *row >= msg_grid.comp_row - && *row < (msg_grid.rows + msg_grid.comp_row) - && *col < msg_grid.cols) { - *grid = &msg_grid; - *row -= msg_grid.comp_row; - } + + *grid = ui_comp_get_grid_at_coord(*row, *col); + + // Make `row` and `col` relative to the grid + *row -= (*grid)->comp_row; + *col -= (*grid)->comp_col; } /// Set line or list of lines in buffer "buf". diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 2225076a0a..8e49d1b9a8 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -7766,6 +7766,9 @@ static int search_cmn(typval_T *argvars, pos_T *match_pos, int *flagsp) break; } } + + // clear the start flag to avoid getting stuck here + options &= ~SEARCH_START; } if (subpatnum != FAIL) { @@ -8035,14 +8038,15 @@ static void f_screenattr(typval_T *argvars, typval_T *rettv, FunPtr fptr) { int c; + ScreenGrid *grid; int row = (int)tv_get_number_chk(&argvars[0], NULL) - 1; int col = (int)tv_get_number_chk(&argvars[1], NULL) - 1; - if (row < 0 || row >= default_grid.rows - || col < 0 || col >= default_grid.cols) { + + screenchar_adjust(&grid, &row, &col); + + if (row < 0 || row >= grid->rows || col < 0 || col >= grid->cols) { c = -1; } else { - ScreenGrid *grid = &default_grid; - screenchar_adjust_grid(&grid, &row, &col); c = grid->attrs[grid->line_offset[row] + col]; } rettv->vval.v_number = c; @@ -8053,14 +8057,15 @@ static void f_screenchar(typval_T *argvars, typval_T *rettv, FunPtr fptr) { int c; + ScreenGrid *grid; int row = tv_get_number_chk(&argvars[0], NULL) - 1; int col = tv_get_number_chk(&argvars[1], NULL) - 1; - if (row < 0 || row >= default_grid.rows - || col < 0 || col >= default_grid.cols) { + + screenchar_adjust(&grid, &row, &col); + + if (row < 0 || row >= grid->rows || col < 0 || col >= grid->cols) { c = -1; } else { - ScreenGrid *grid = &default_grid; - screenchar_adjust_grid(&grid, &row, &col); c = utf_ptr2char((char *)grid->chars[grid->line_offset[row] + col]); } rettv->vval.v_number = c; @@ -8069,15 +8074,16 @@ static void f_screenchar(typval_T *argvars, typval_T *rettv, FunPtr fptr) /// "screenchars()" function static void f_screenchars(typval_T *argvars, typval_T *rettv, FunPtr fptr) { + ScreenGrid *grid; int row = tv_get_number_chk(&argvars[0], NULL) - 1; int col = tv_get_number_chk(&argvars[1], NULL) - 1; - if (row < 0 || row >= default_grid.rows - || col < 0 || col >= default_grid.cols) { + + screenchar_adjust(&grid, &row, &col); + + if (row < 0 || row >= grid->rows || col < 0 || col >= grid->cols) { tv_list_alloc_ret(rettv, 0); return; } - ScreenGrid *grid = &default_grid; - screenchar_adjust_grid(&grid, &row, &col); int pcc[MAX_MCO]; int c = utfc_ptr2char(grid->chars[grid->line_offset[row] + col], pcc); int composing_len = 0; @@ -8136,14 +8142,17 @@ static void f_screenstring(typval_T *argvars, typval_T *rettv, FunPtr fptr) { rettv->vval.v_string = NULL; rettv->v_type = VAR_STRING; + + ScreenGrid *grid; int row = tv_get_number_chk(&argvars[0], NULL) - 1; int col = tv_get_number_chk(&argvars[1], NULL) - 1; - if (row < 0 || row >= default_grid.rows - || col < 0 || col >= default_grid.cols) { + + screenchar_adjust(&grid, &row, &col); + + if (row < 0 || row >= grid->rows || col < 0 || col >= grid->cols) { return; } - ScreenGrid *grid = &default_grid; - screenchar_adjust_grid(&grid, &row, &col); + rettv->vval.v_string = (char *)vim_strsave(grid->chars[grid->line_offset[row] + col]); } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index a65e89a9f5..49db5c3716 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2826,10 +2826,13 @@ int parse_cmd_address(exarg_T *eap, char **errormsg, bool silent) curwin->w_cursor.lnum = eap->line2; // Don't leave the cursor on an illegal line or column, but do - // accept zero as address, so 0;/PATTERN/ works correctly. + // accept zero as address, so 0;/PATTERN/ works correctly + // (where zero usually means to use the first line). // Check the cursor position before returning. if (eap->line2 > 0) { check_cursor(); + } else { + check_cursor_col(); } need_check_cursor = true; } diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 7f783fd72f..57d25e5c45 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -2122,6 +2122,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) const bool save_may_garbage_collect = may_garbage_collect; const int save_cursor_row = ui_current_row(); const int save_cursor_col = ui_current_col(); + const handle_T save_cursor_grid = ui_cursor_grid(); const int prev_did_emsg = did_emsg; vgetc_busy = 0; @@ -2135,7 +2136,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth) // The mapping may do anything, but we expect it to take care of // redrawing. Do put the cursor back where it was. - ui_cursor_goto(save_cursor_row, save_cursor_col); + ui_grid_cursor_goto(save_cursor_grid, save_cursor_row, save_cursor_col); ui_flush(); // If an error was displayed and the expression returns an empty diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 010d2fe869..d71b3adb5c 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -697,8 +697,10 @@ int get_lisp_indent(void) && lisp_match(that + 1)) { amount += 2; } else { - that++; - amount++; + if (*that != NUL) { + that++; + amount++; + } firsttry = amount; while (ascii_iswhite(*that)) { diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 47305b6709..0d43458b5b 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -2381,8 +2381,6 @@ static void update_si_attr(int idx) } else { sip->si_attr = CUR_STATE(idx - 1).si_attr; sip->si_trans_id = CUR_STATE(idx - 1).si_trans_id; - sip->si_h_startpos = CUR_STATE(idx - 1).si_h_startpos; - sip->si_h_endpos = CUR_STATE(idx - 1).si_h_endpos; if (sip->si_cont_list == NULL) { sip->si_flags |= HL_TRANS_CONT; sip->si_cont_list = CUR_STATE(idx - 1).si_cont_list; diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index b2c752376f..d26c80077d 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -636,6 +636,14 @@ func Test_illegal_address2() call delete('Xtest.vim') endfunc +func Test_mark_from_line_zero() + " this was reading past the end of the first (empty) line + new + norm oxxxx + call assert_fails("0;'(", 'E20:') + bwipe! +endfunc + func Test_cmdline_complete_wildoptions() help call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') diff --git a/src/nvim/testdir/test_lispwords.vim b/src/nvim/testdir/test_lispwords.vim index ff710b2716..4144fb0521 100644 --- a/src/nvim/testdir/test_lispwords.vim +++ b/src/nvim/testdir/test_lispwords.vim @@ -1,4 +1,5 @@ -" Tests for 'lispwords' settings being global-local +" Tests for 'lispwords' settings being global-local. +" And other lisp indent stuff. set nocompatible viminfo+=nviminfo @@ -85,4 +86,13 @@ func Test_lisp_indent() set nolisp endfunc +func Test_lisp_indent_works() + " This was reading beyond the end of the line + new + exe "norm a\tü(\<CR>=" + set lisp + norm == + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 6bef61ae8f..9f50b3c241 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -745,8 +745,9 @@ func Test_search_syntax_skip() 1 call search('VIM', 'w', '', 0, 'synIDattr(synID(line("."), col("."), 1), "name") =~? "comment"') call assert_equal('Another Text for VIM', getline('.')) + 1 - call search('VIM', 'w', '', 0, 'synIDattr(synID(line("."), col("."), 1), "name") !~? "string"') + call search('VIM', 'cw', '', 0, 'synIDattr(synID(line("."), col("."), 1), "name") !~? "string"') call assert_equal(' let a = "VIM"', getline('.')) " Skip argument using Lambda. @@ -755,29 +756,106 @@ func Test_search_syntax_skip() call assert_equal('Another Text for VIM', getline('.')) 1 - call search('VIM', 'w', '', 0, { -> synIDattr(synID(line("."), col("."), 1), "name") !~? "string"}) + call search('VIM', 'cw', '', 0, { -> synIDattr(synID(line("."), col("."), 1), "name") !~? "string"}) call assert_equal(' let a = "VIM"', getline('.')) " Skip argument using funcref. func InComment() return synIDattr(synID(line("."), col("."), 1), "name") =~? "comment" endfunc - func InString() + func NotInString() return synIDattr(synID(line("."), col("."), 1), "name") !~? "string" endfunc + 1 call search('VIM', 'w', '', 0, function('InComment')) call assert_equal('Another Text for VIM', getline('.')) 1 - call search('VIM', 'w', '', 0, function('InString')) + call search('VIM', 'cw', '', 0, function('NotInString')) call assert_equal(' let a = "VIM"', getline('.')) delfunc InComment - delfunc InString + delfunc NotInString bwipe! endfunc +func Test_syn_contained_transparent() + " Comments starting with "Regression:" show the result when the highlighting + " span of the containing item is assigned to the contained region. + syntax on + + let l:case = "Transparent region contained in region" + new + syntax region X start=/\[/ end=/\]/ contained transparent + syntax region Y start=/(/ end=/)/ contains=X + + call setline(1, "==(--[~~]--)==") + let l:expected = " YYYYYYYYYY " + eval AssertHighlightGroups(1, 1, l:expected, 1, l:case) + syntax clear Y X + bw! + + let l:case = "Transparent region extends region" + new + syntax region X start=/\[/ end=/\]/ contained transparent + syntax region Y start=/(/ end=/)/ end=/e/ contains=X + + call setline(1, "==(--[~~e~~]--)==") + let l:expected = " YYYYYYYYYYYYY " + " Regression: " YYYYYYY YYY " + eval AssertHighlightGroups(1, 1, l:expected, 1, l:case) + syntax clear Y X + bw! + + let l:case = "Nested transparent regions extend region" + new + syntax region X start=/\[/ end=/\]/ contained transparent + syntax region Y start=/(/ end=/)/ end=/e/ contains=X + + call setline(1, "==(--[~~e~~[~~e~~]~~e~~]--)==") + let l:expected = " YYYYYYYYYYYYYYYYYYYYYYYYY " + " Regression: " YYYYYYY YYYYYYYYY " + eval AssertHighlightGroups(1, 1, l:expected, 1, l:case) + syntax clear Y X + bw! + + let l:case = "Transparent region contained in match" + new + syntax region X start=/\[/ end=/\]/ contained transparent + syntax match Y /(.\{-})/ contains=X + + call setline(1, "==(--[~~]--)==") + let l:expected = " YYYYYYYYYY " + eval AssertHighlightGroups(1, 1, l:expected, 1, l:case) + syntax clear Y X + bw! + + let l:case = "Transparent region extends match" + new + syntax region X start=/\[/ end=/\]/ contained transparent + syntax match Y /(.\{-}[e)]/ contains=X + + call setline(1, "==(--[~~e~~]--)==") + let l:expected = " YYYYYYYYYY " + " Regression: " YYYYYYY " + eval AssertHighlightGroups(1, 1, l:expected, 1, l:case) + syntax clear Y X + bw! + + let l:case = "Nested transparent regions extend match" + new + syntax region X start=/\[/ end=/\]/ contained transparent + syntax match Y /(.\{-}[e)]/ contains=X + + call setline(1, "==(--[~~e~~[~~e~~]~~e~~]--)==") + let l:expected = " YYYYYYYYYYYYYYYYYYYYYY " + " Regression: " YYYYYYY YYYYYY " + eval AssertHighlightGroups(1, 1, l:expected, 1, l:case) + syntax clear Y X + bw! +endfunc + func Test_syn_include_contains_TOP() let l:case = "TOP in included syntax means its group list name" new diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 96ce2c4cb1..a49e9df9ee 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -495,6 +495,11 @@ int ui_current_col(void) return cursor_col; } +handle_T ui_cursor_grid(void) +{ + return cursor_grid_handle; +} + void ui_flush(void) { cmdline_ui_flush(); diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 3ce2b80ea9..5df70d0d8e 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -300,6 +300,19 @@ ScreenGrid *ui_comp_mouse_focus(int row, int col) return NULL; } +/// Compute which grid is on top at supplied screen coordinates +ScreenGrid *ui_comp_get_grid_at_coord(int row, int col) +{ + for (ssize_t i = (ssize_t)kv_size(layers) - 1; i > 0; i--) { + ScreenGrid *grid = kv_A(layers, i); + if (row >= grid->comp_row && row < grid->comp_row + grid->rows + && col >= grid->comp_col && col < grid->comp_col + grid->cols) { + return grid; + } + } + return &default_grid; +} + /// Baseline implementation. This is always correct, but we can sometimes /// do something more efficient (where efficiency means smaller deltas to /// the downstream UI.) diff --git a/test/functional/ex_cmds/map_spec.lua b/test/functional/ex_cmds/map_spec.lua index eae36b9ae9..c6bdd017bd 100644 --- a/test/functional/ex_cmds/map_spec.lua +++ b/test/functional/ex_cmds/map_spec.lua @@ -86,7 +86,7 @@ n asdf1 qwert end) end) -describe(':*map cursor and redrawing', function() +describe('Screen', function() local screen before_each(function() clear() @@ -149,6 +149,18 @@ describe(':*map cursor and redrawing', function() ]]) end) + it('cursor position does not move after empty-string :cmap <expr> #19046', function() + command([[cnoremap <expr> <F2> '']]) + feed(':<F2>') + screen:expect([[ + | + ~ | + ~ | + ~ | + :^ | + ]]) + end) + it('cursor is restored after :map <expr> which redraws statusline vim-patch:8.1.2336', function() exec([[ call setline(1, ['one', 'two', 'three']) @@ -157,12 +169,12 @@ describe(':*map cursor and redrawing', function() hi! link StatusLine ErrorMsg noremap <expr> <C-B> Func() func Func() - let g:on = !get(g:, 'on', 0) - redraws - return '' + let g:on = !get(g:, 'on', 0) + redraws + return '' endfunc func Status() - return get(g:, 'on', 0) ? '[on]' : '' + return get(g:, 'on', 0) ? '[on]' : '' endfunc set stl=%{Status()} ]]) diff --git a/test/functional/fixtures/CMakeLists.txt b/test/functional/fixtures/CMakeLists.txt index 270540de2e..6010fcaf1e 100644 --- a/test/functional/fixtures/CMakeLists.txt +++ b/test/functional/fixtures/CMakeLists.txt @@ -4,7 +4,7 @@ target_link_libraries(tty-test ${LIBUV_LIBRARIES}) add_executable(shell-test EXCLUDE_FROM_ALL shell-test.c) add_executable(printargs-test EXCLUDE_FROM_ALL printargs-test.c) add_executable(printenv-test EXCLUDE_FROM_ALL printenv-test.c) -if(WIN32) +if(MINGW) set_target_properties(printenv-test PROPERTIES LINK_FLAGS -municode) endif() diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 44e65afc78..646c5ac8ca 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1400,6 +1400,8 @@ describe('lua stdlib', function() pcall_err(exec_lua, 'return vim.bo.nosuchopt')) matches("Expected lua string$", pcall_err(exec_lua, 'return vim.bo[0][0].autoread')) + matches("Invalid buffer id: %-1$", + pcall_err(exec_lua, 'return vim.bo[-1].filetype')) end) it('vim.wo', function() @@ -1419,6 +1421,8 @@ describe('lua stdlib', function() pcall_err(exec_lua, 'return vim.wo.notanopt')) matches("Expected lua string$", pcall_err(exec_lua, 'return vim.wo[0][0].list')) + matches("Invalid window id: %-1$", + pcall_err(exec_lua, 'return vim.wo[-1].list')) eq(2, funcs.luaeval "vim.wo[1000].cole") exec_lua [[ vim.wo[1000].cole = 0 diff --git a/test/functional/vimscript/screenchar_spec.lua b/test/functional/vimscript/screenchar_spec.lua new file mode 100644 index 0000000000..767e3c57ef --- /dev/null +++ b/test/functional/vimscript/screenchar_spec.lua @@ -0,0 +1,69 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear, eq, neq = helpers.clear, helpers.eq, helpers.neq +local command, meths, funcs = helpers.command, helpers.meths, helpers.funcs +local tbl_deep_extend = helpers.tbl_deep_extend + +-- Set up two overlapping floating windows +local setup_floating_windows = function() + local base_opts = { + relative = 'editor', + height = 1, + width = 2, + anchor = 'NW', + style = 'minimal', + border = 'none', + } + + local bufnr_1 = meths.create_buf(false, true) + meths.buf_set_lines(bufnr_1, 0, -1, true, { 'aa' }) + local opts_1 = tbl_deep_extend('force', { row = 0, col = 0, zindex = 11 }, base_opts) + meths.open_win(bufnr_1, false, opts_1) + + local bufnr_2 = meths.create_buf(false, true) + meths.buf_set_lines(bufnr_2, 0, -1, true, { 'bb' }) + local opts_2 = tbl_deep_extend('force', { row = 0, col = 1, zindex = 10 }, base_opts) + meths.open_win(bufnr_2, false, opts_2) + + command('redraw') +end + +describe('screenchar() and family respect floating windows', function() + before_each(function() + clear() + -- These commands result into visible text `aabc`. + -- `aab` - from floating windows, `c` - from text in regular window. + meths.buf_set_lines(0, 0, -1, true, { 'cccc' }) + setup_floating_windows() + end) + + it('screenattr()', function() + local attr_1 = funcs.screenattr(1, 1) + local attr_2 = funcs.screenattr(1, 2) + local attr_3 = funcs.screenattr(1, 3) + local attr_4 = funcs.screenattr(1, 4) + eq(attr_1, attr_2) + eq(attr_1, attr_3) + neq(attr_1, attr_4) + end) + + it('screenchar()', function() + eq(97, funcs.screenchar(1, 1)) + eq(97, funcs.screenchar(1, 2)) + eq(98, funcs.screenchar(1, 3)) + eq(99, funcs.screenchar(1, 4)) + end) + + it('screenchars()', function() + eq({ 97 }, funcs.screenchars(1, 1)) + eq({ 97 }, funcs.screenchars(1, 2)) + eq({ 98 }, funcs.screenchars(1, 3)) + eq({ 99 }, funcs.screenchars(1, 4)) + end) + + it('screenstring()', function() + eq('a', funcs.screenstring(1, 1)) + eq('a', funcs.screenstring(1, 2)) + eq('b', funcs.screenstring(1, 3)) + eq('c', funcs.screenstring(1, 4)) + end) +end) |