From 5b87e58c5a54baf7d30ffe187392191cbe8c5115 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 31 Oct 2023 14:55:51 +0800 Subject: [PATCH] fix(terminal): keep focus when scrolling number column of another window (cherry picked from commit ca0a603bce8c5d1f6f373a4526a4fa4231e64e40) --- src/nvim/terminal.c | 7 ++++--- test/functional/terminal/mouse_spec.lua | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 782a37d6ed..ac29dbc0eb 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -1416,13 +1416,14 @@ static void mouse_action(Terminal *term, int button, int row, int col, bool pres static bool send_mouse_event(Terminal *term, int c) { int row = mouse_row, col = mouse_col, grid = mouse_grid; - int offset; win_T *mouse_win = mouse_find_win(&grid, &row, &col); - if (mouse_win == NULL || (offset = win_col_off(mouse_win)) > col) { + if (mouse_win == NULL) { goto end; } - if (term->forward_mouse && mouse_win->w_buffer->terminal == term) { + int offset; + if (term->forward_mouse && mouse_win->w_buffer->terminal == term + && col >= (offset = win_col_off(mouse_win))) { // 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 6591a93d69..944fc4f48a 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -338,7 +338,7 @@ describe(':terminal mouse', function() {3:-- TERMINAL --} | ]]) command('set mousescroll=ver:10') - feed('<4,0>') + feed('<0,0>') screen:expect([[ {7: 16 }line │line30 | {7: 17 }line │rows: 5, cols: 25 | @@ -349,7 +349,7 @@ describe(':terminal mouse', function() {3:-- TERMINAL --} | ]]) command('set mousescroll=ver:0') - feed('<4,0>') + feed('<0,0>') screen:expect_unchanged() end)