diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2017-03-20 00:47:27 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-03-20 00:47:27 +0100 | 
| commit | 091a99afd43126d5e25fd6ea3f19f531a1b5cb9c (patch) | |
| tree | b9cebfa51815137e8c26b9d3581106e551aba81d /src/nvim/cursor.c | |
| parent | 0cab62ad6fc642c06e4249dccac092dd71b0cb3e (diff) | |
| parent | 2f54d6927cc02484b528a5e8b25b64c8d6580ddd (diff) | |
| download | rneovim-091a99afd43126d5e25fd6ea3f19f531a1b5cb9c.tar.gz rneovim-091a99afd43126d5e25fd6ea3f19f531a1b5cb9c.tar.bz2 rneovim-091a99afd43126d5e25fd6ea3f19f531a1b5cb9c.zip | |
Merge #6318 from justinmk/pr6244
test/legacy: fix test_normal.vim
Diffstat (limited to 'src/nvim/cursor.c')
| -rw-r--r-- | src/nvim/cursor.c | 20 | 
1 files changed, 20 insertions, 0 deletions
| diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 3ba9da34f2..544bcf6ede 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -294,6 +294,26 @@ linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum)    return (lnum < cursor) ? -retval : retval;  } +// Make sure "pos.lnum" and "pos.col" are valid in "buf". +// This allows for the col to be on the NUL byte. +void check_pos(buf_T *buf, pos_T *pos) +{ +  char_u *line; +  colnr_T len; + +  if (pos->lnum > buf->b_ml.ml_line_count) { +     pos->lnum = buf->b_ml.ml_line_count; +  } + +  if (pos->col > 0) { +     line = ml_get_buf(buf, pos->lnum, false); +     len = (colnr_T)STRLEN(line); +     if (pos->col > len) { +         pos->col = len; +     } +  } +} +  /*   * Make sure curwin->w_cursor.lnum is valid.   */ | 
