aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/edit.c6
-rw-r--r--src/nvim/eval.c3
-rw-r--r--src/nvim/mouse.c13
-rw-r--r--src/nvim/normal.c6
4 files changed, 25 insertions, 3 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index cdccb57eee..4e4ca1f8f3 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -7884,7 +7884,11 @@ static void ins_mousescroll(int dir)
col = mouse_col;
/* find the window at the pointer coordinates */
- curwin = mouse_find_win(&row, &col);
+ win_T *const wp = mouse_find_win(&row, &col);
+ if (wp == NULL) {
+ return;
+ }
+ curwin = wp;
curbuf = curwin->w_buffer;
}
if (curwin == old_curwin)
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 15b5c3eef3..3abc39e7bf 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -9493,6 +9493,9 @@ static void f_getchar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
/* Find the window at the mouse coordinates and compute the
* text position. */
win = mouse_find_win(&row, &col);
+ if (win == NULL) {
+ return;
+ }
(void)mouse_comp_pos(win, &row, &col, &lnum);
for (wp = firstwin; wp != win; wp = wp->w_next)
++winnr;
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c
index 8c615f52e7..3c792326a4 100644
--- a/src/nvim/mouse.c
+++ b/src/nvim/mouse.c
@@ -125,6 +125,9 @@ retnomove:
// find the window where the row is in
wp = mouse_find_win(&row, &col);
+ if (wp == NULL) {
+ return IN_UNKNOWN;
+ }
dragwin = NULL;
// winpos and height may change in win_enter()!
if (row >= wp->w_height) { // In (or below) status line
@@ -427,6 +430,7 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump)
// Find the window at screen position "*rowp" and "*colp". The positions are
// updated to become relative to the top-left of the window.
+// Returns NULL when something is wrong.
win_T *mouse_find_win(int *rowp, int *colp)
{
frame_T *fp;
@@ -450,7 +454,14 @@ win_T *mouse_find_win(int *rowp, int *colp)
}
}
}
- return fp->fr_win;
+ // When using a timer that closes a window the window might not actually
+ // exist.
+ FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
+ if (wp == fp->fr_win) {
+ return wp;
+ }
+ }
+ return NULL;
}
/*
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index a695620801..001972103c 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -3995,7 +3995,11 @@ static void nv_mousescroll(cmdarg_T *cap)
col = mouse_col;
/* find the window at the pointer coordinates */
- curwin = mouse_find_win(&row, &col);
+ win_T *const wp = mouse_find_win(&row, &col);
+ if (wp == NULL) {
+ return;
+ }
+ curwin = wp;
curbuf = curwin->w_buffer;
}