fix(terminal): check if mouse on statusline/tabline/winbar/vsep (#26892)

This commit is contained in:
zeertzjq 2024-01-05 10:59:52 +08:00 committed by GitHub
parent dab5844082
commit e09adfdcff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 134 additions and 4 deletions

View File

@ -229,7 +229,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;
}
@ -1249,7 +1249,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

View File

@ -1437,8 +1437,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;

View File

@ -243,6 +243,134 @@ describe(':terminal mouse', function()
{3:-- TERMINAL --} |
]])
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)
end)
describe('with a split window and other buffer', function()