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)

99d19438ca

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq 2022-12-06 07:52:00 +08:00
parent 10af0549df
commit 0909d987fe
3 changed files with 9 additions and 0 deletions

View File

@ -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"));

View File

@ -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);

View File

@ -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