Summary Files Commits Branches @commit @diff @stats
path: root / overlays / neovim / 26892.patch
blob: 8a66d54ec5aaa86b7b2ceffbac2bb651b67591d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
From 16a6ccbff41538d8370b6c231d05c0fc1198989c Mon Sep 17 00:00:00 2001
From: zeertzjq <zeertzjq@outlook.com>
Date: Tue, 6 Aug 2024 17:16:48 +0300
Subject: [PATCH] [PATCH] fix(terminal): check if mouse on

Modified to work with with v0.9.5 by Syndamia
---
 src/nvim/mouse.c                        |   4 +-
 src/nvim/terminal.c                     |   6 +-
 test/functional/terminal/mouse_spec.lua | 129 ++++++++++++++++++++++++
 3 files changed, 135 insertions(+), 4 deletions(-)

diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c
index a4f4a49fc..a23a15e49 100644
--- a/src/nvim/mouse.c
+++ b/src/nvim/mouse.c
@@ -234,7 +234,7 @@ static int get_fpos_of_mouse(pos_T *mpos)
     return IN_STATUS_LINE;
   }
 
-  if (winrow == -1 && wp->w_winbar_height != 0) {
+  if (winrow < 0 && winrow + wp->w_winbar_height >= 0) {
     return MOUSE_WINBAR;
   }
 
@@ -1118,7 +1118,7 @@ retnomove:
   bool below_window = grid == DEFAULT_GRID_HANDLE && row + wp->w_winbar_height >= wp->w_height;
   on_status_line = below_window && row + wp->w_winbar_height - wp->w_height + 1 == 1;
   on_sep_line = grid == DEFAULT_GRID_HANDLE && col >= wp->w_width && col - wp->w_width + 1 == 1;
-  on_winbar = row == -1 && wp->w_winbar_height != 0;
+  on_winbar = row < 0 && row + wp->w_winbar_height >= 0;
   on_statuscol = !below_window && !on_status_line && !on_sep_line && !on_winbar
                  && *wp->w_p_stc != NUL
                  && (wp->w_p_rl
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index ac29dbc0e..e1efeed61 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -1422,8 +1422,10 @@ static bool send_mouse_event(Terminal *term, int c)
   }
 
   int offset;
-  if (term->forward_mouse && mouse_win->w_buffer->terminal == term
-      && col >= (offset = win_col_off(mouse_win))) {
+  if (term->forward_mouse && mouse_win->w_buffer->terminal == term && row >= 0
+      && (grid > 1 || row + mouse_win->w_winbar_height < mouse_win->w_height)
+      && col >= (offset = win_col_off(mouse_win))
+      && (grid > 1 || col < mouse_win->w_width)) {
     // event in the terminal window and mouse events was enabled by the
     // program. translate and forward the event
     int button;
diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua
index 944fc4f48..d2c55b368 100644
--- a/test/functional/terminal/mouse_spec.lua
+++ b/test/functional/terminal/mouse_spec.lua
@@ -245,6 +245,135 @@ describe(':terminal mouse', function()
       end)
     end)
 
+      it('will lose focus if statusline is clicked', function()
+        command('set laststatus=2')
+        screen:expect([[
+          line29                                            |
+          line30                                            |
+          mouse enabled                                     |
+          rows: 5, cols: 50                                 |
+          {1: }                                                 |
+          ==========                                        |
+          {3:-- TERMINAL --}                                    |
+        ]])
+        feed('<LeftMouse><0,5>')
+        screen:expect([[
+          line29                                            |
+          line30                                            |
+          mouse enabled                                     |
+          rows: 5, cols: 50                                 |
+          {2:^ }                                                 |
+          ==========                                        |
+                                                            |
+        ]])
+        feed('<LeftDrag><0,4>')
+        screen:expect([[
+          mouse enabled                                     |
+          rows: 5, cols: 50                                 |
+          rows: 4, cols: 50                                 |
+          {2:^ }                                                 |
+          ==========                                        |
+                                                            |*2
+        ]])
+      end)
+
+      it('will lose focus if right separator is clicked', function()
+        command('rightbelow vnew | wincmd p | startinsert')
+        screen:expect([[
+          line29                  │                         |
+          line30                  │{4:~                        }|
+          mouse enabled           │{4:~                        }|
+          rows: 5, cols: 24       │{4:~                        }|
+          {1: }                       │{4:~                        }|
+          ==========               ==========               |
+          {3:-- TERMINAL --}                                    |
+        ]])
+        feed('<LeftMouse><24,0>')
+        screen:expect([[
+          line29                  │                         |
+          line30                  │{4:~                        }|
+          mouse enabled           │{4:~                        }|
+          rows: 5, cols: 24       │{4:~                        }|
+          {2:^ }                       │{4:~                        }|
+          ==========               ==========               |
+                                                            |
+        ]])
+        feed('<LeftDrag><23,0>')
+        screen:expect([[
+          line30                 │                          |
+          mouse enabled          │{4:~                         }|
+          rows: 5, cols: 24      │{4:~                         }|
+          rows: 5, cols: 23      │{4:~                         }|
+          {2:^ }                      │{4:~                         }|
+          ==========              ==========                |
+                                                            |
+        ]])
+      end)
+
+      it('will lose focus if winbar/tabline is clicked', function()
+        command('setlocal winbar=WINBAR')
+        screen:expect([[
+          {3:WINBAR                                            }|
+          line29                                            |
+          line30                                            |
+          mouse enabled                                     |
+          rows: 5, cols: 50                                 |
+          {1: }                                                 |
+          {3:-- TERMINAL --}                                    |
+        ]])
+        feed('<LeftMouse><0,0>')
+        screen:expect([[
+          {3:WINBAR                                            }|
+          line29                                            |
+          line30                                            |
+          mouse enabled                                     |
+          rows: 5, cols: 50                                 |
+          {2:^ }                                                 |
+                                                            |
+        ]])
+        command('set showtabline=2 tabline=TABLINE | startinsert')
+        screen:expect([[
+          {1:TABLINE                                           }|
+          {3:WINBAR                                            }|
+          mouse enabled                                     |
+          rows: 5, cols: 50                                 |
+          rows: 4, cols: 50                                 |
+          {1: }                                                 |
+          {3:-- TERMINAL --}                                    |
+        ]])
+        feed('<LeftMouse><0,0>')
+        screen:expect([[
+          {1:TABLINE                                           }|
+          {3:WINBAR                                            }|
+          mouse enabled                                     |
+          rows: 5, cols: 50                                 |
+          rows: 4, cols: 50                                 |
+          {2:^ }                                                 |
+                                                            |
+        ]])
+        command('setlocal winbar= | startinsert')
+        screen:expect([[
+          {1:TABLINE                                           }|
+          mouse enabled                                     |
+          rows: 5, cols: 50                                 |
+          rows: 4, cols: 50                                 |
+          rows: 5, cols: 50                                 |
+          {1: }                                                 |
+          {3:-- TERMINAL --}                                    |
+        ]])
+        feed('<LeftMouse><0,0>')
+        screen:expect([[
+          {1:TABLINE                                           }|
+          mouse enabled                                     |
+          rows: 5, cols: 50                                 |
+          rows: 4, cols: 50                                 |
+          rows: 5, cols: 50                                 |
+          {2:^ }                                                 |
+                                                            |
+        ]])
+      end)
+
+
     describe('with a split window and other buffer', function()
       before_each(function()
         feed('<c-\\><c-n>:vsp<cr>')
-- 
2.44.1