diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-12-06 07:52:00 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-12-06 08:00:17 +0800 |
commit | 0909d987fe925483dc513ae330179339899cd0a5 (patch) | |
tree | a1d31135893f8f50bec0290bce93c78e8b4ba53f | |
parent | 10af0549df7ac4ea9907b34624228755b9752318 (diff) | |
download | rneovim-0909d987fe925483dc513ae330179339899cd0a5.tar.gz rneovim-0909d987fe925483dc513ae330179339899cd0a5.tar.bz2 rneovim-0909d987fe925483dc513ae330179339899cd0a5.zip |
vim-patch:9.0.1011: ml_get error when using screenpos()
Problem: ml_get error when using screenpos().
Solution: Give an error for the line number. (closes vim/vim#11661)
https://github.com/vim/vim/commit/99d19438cabaf13074229d9a32e3a4af9ce98744
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/globals.h | 2 | ||||
-rw-r--r-- | src/nvim/move.c | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test_cursor_func.vim | 3 |
3 files changed, 9 insertions, 0 deletions
diff --git a/src/nvim/globals.h b/src/nvim/globals.h index c05e49e9a9..0169b62188 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -1023,6 +1023,8 @@ EXTERN char e_highlight_group_name_invalid_char[] INIT(= N_("E5248: Invalid char EXTERN char e_highlight_group_name_too_long[] INIT(= N_("E1249: Highlight group name too long")); +EXTERN char e_invalid_line_number_nr[] INIT(= N_("E966: Invalid line number: %ld")); + EXTERN char e_undobang_cannot_redo_or_move_branch[] INIT(= N_("E5767: Cannot use :undo! to redo or move to a different undo branch")); diff --git a/src/nvim/move.c b/src/nvim/move.c index dda5e33d2b..17e3ef74cc 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -996,6 +996,10 @@ void f_screenpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) .col = (colnr_T)tv_get_number(&argvars[2]) - 1, .coladd = 0 }; + if (pos.lnum > wp->w_buffer->b_ml.ml_line_count) { + semsg(_(e_invalid_line_number_nr), pos.lnum); + return; + } int row = 0; int scol = 0, ccol = 0, ecol = 0; textpos2screenpos(wp, &pos, &row, &scol, &ccol, &ecol, false); diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index ad78adfc09..634b27b0ed 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -155,6 +155,9 @@ func Test_screenpos_number() let pos = screenpos(winid, 1, 66) call assert_equal(winrow, pos.row) call assert_equal(wincol + 66 + 3, pos.col) + + call assert_fails('echo screenpos(0, 2, 1)', 'E966:') + close bwipe! endfunc |