aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/cursor.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
commit9be89f131f87608f224f0ee06d199fcd09d32176 (patch)
tree11022dcfa9e08cb4ac5581b16734196128688d48 /src/nvim/cursor.c
parentff7ed8f586589d620a806c3758fac4a47a8e7e15 (diff)
parent88085c2e80a7e3ac29aabb6b5420377eed99b8b6 (diff)
downloadrneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.gz
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.bz2
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'src/nvim/cursor.c')
-rw-r--r--src/nvim/cursor.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c
index 2e9e68843a..35afca2fe9 100644
--- a/src/nvim/cursor.c
+++ b/src/nvim/cursor.c
@@ -216,12 +216,7 @@ static int coladvance2(win_T *wp, pos_T *pos, bool addspaces, bool finetune, col
}
}
- if (idx < 0) {
- pos->col = 0;
- } else {
- pos->col = idx;
- }
-
+ pos->col = MAX(idx, 0);
pos->coladd = 0;
if (finetune) {
@@ -310,15 +305,9 @@ linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum)
/// This allows for the col to be on the NUL byte.
void check_pos(buf_T *buf, pos_T *pos)
{
- if (pos->lnum > buf->b_ml.ml_line_count) {
- pos->lnum = buf->b_ml.ml_line_count;
- }
-
+ pos->lnum = MIN(pos->lnum, buf->b_ml.ml_line_count);
if (pos->col > 0) {
- colnr_T len = ml_get_buf_len(buf, pos->lnum);
- if (pos->col > len) {
- pos->col = len;
- }
+ pos->col = MIN(pos->col, ml_get_buf_len(buf, pos->lnum));
}
}
@@ -385,9 +374,7 @@ void check_cursor_col(win_T *win)
int cs, ce;
getvcol(win, &win->w_cursor, &cs, NULL, &ce);
- if (win->w_cursor.coladd > ce - cs) {
- win->w_cursor.coladd = ce - cs;
- }
+ win->w_cursor.coladd = MIN(win->w_cursor.coladd, ce - cs);
}
} else {
// avoid weird number when there is a miscalculation or overflow