From 6d550f3cdbca6091042526a0153e0db18192447e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 1 Oct 2025 09:24:02 +0800 Subject: [PATCH] test(terminal/mouse_spec): forwarding works with resized grid (#35969) --- src/nvim/plines.c | 7 ++- test/functional/terminal/mouse_spec.lua | 83 ++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/nvim/plines.c b/src/nvim/plines.c index b1d5daf5d9..655a0ee002 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -930,8 +930,9 @@ int plines_m_win(win_T *wp, linenr_T first, linenr_T last, int max) return MIN(max, count); } -/// Return number of window lines a physical line range will occupy. -/// Only considers real and filler lines. +/// Return total number of physical and filler lines in a physical line range. +/// Doesn't treat a fold as a single line or consider a wrapped line multiple lines, +/// unlike plines_m_win() or win_text_height(). /// /// Mainly used for calculating scrolling offsets. int plines_m_win_fill(win_T *wp, linenr_T first, linenr_T last) @@ -940,7 +941,7 @@ int plines_m_win_fill(win_T *wp, linenr_T first, linenr_T last) if (diffopt_filler()) { for (int lnum = first; lnum <= last; lnum++) { - // Note: this also considers folds. + // Note: this also considers folds (no filler lines inside folds). int n = diff_check_fill(wp, lnum); count += MAX(n, 0); } diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 86c58d5ab5..3dc68e394a 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -99,7 +99,7 @@ describe(':terminal mouse', function() describe('with mouse events enabled by the program', function() before_each(function() - tt.enable_mouse() + tt.enable_mouse() -- FIXME: this doesn't work on Windows? tt.feed_data('mouse enabled\n') screen:expect([[ line27 | @@ -381,6 +381,87 @@ describe(':terminal mouse', function() | ]]) end) + + it('mouse forwarding works with resized grid', function() + skip(is_os('win')) + + screen:detach() + local Screen = require('test.functional.ui.screen') + screen = Screen.new(50, 7, { ext_multigrid = true }) + screen:expect([[ + ## grid 1 + [2:--------------------------------------------------]|*6 + [3:--------------------------------------------------]| + ## grid 2 + line27 | + line28 | + line29 | + line30 | + mouse enabled | + ^ | + ## grid 3 + {5:-- TERMINAL --} | + ]]) + + screen:try_resize_grid(2, 58, 11) + screen:expect({ any = vim.pesc('rows: 11, cols: 58') }) + + api.nvim_input_mouse('right', 'press', '', 2, 0, 0) + screen:expect({ any = vim.pesc('"!!^') }) + api.nvim_input_mouse('right', 'release', '', 2, 0, 0) + screen:expect({ any = vim.pesc('#!!^') }) + + api.nvim_input_mouse('right', 'press', '', 2, 10, 0) + screen:expect({ any = vim.pesc('"!+^') }) + api.nvim_input_mouse('right', 'release', '', 2, 10, 0) + screen:expect({ any = vim.pesc('#!+^') }) + + api.nvim_input_mouse('right', 'press', '', 2, 0, 57) + screen:expect({ any = vim.pesc('"Z!^') }) + api.nvim_input_mouse('right', 'release', '', 2, 0, 57) + screen:expect({ any = vim.pesc('#Z!^') }) + + api.nvim_input_mouse('right', 'press', '', 2, 10, 57) + screen:expect({ any = vim.pesc('"Z+^') }) + api.nvim_input_mouse('right', 'release', '', 2, 10, 57) + screen:expect({ any = vim.pesc('#Z+^') }) + + command('setlocal winbar=WINBAR') + screen:expect({ any = vim.pesc(('{5:WINBAR%s}'):format((' '):rep(52))) }) + eq('t', api.nvim_get_mode().mode) + + api.nvim_input_mouse('right', 'press', '', 2, 0, 0) + eq('nt', api.nvim_get_mode().mode) + api.nvim_input_mouse('right', 'release', '', 2, 0, 0) + feed('i') + eq('t', api.nvim_get_mode().mode) + + api.nvim_input_mouse('right', 'press', '', 2, 0, 57) + eq('nt', api.nvim_get_mode().mode) + api.nvim_input_mouse('right', 'release', '', 2, 0, 57) + feed('i') + eq('t', api.nvim_get_mode().mode) + + api.nvim_input_mouse('right', 'press', '', 2, 1, 0) + screen:expect({ any = vim.pesc('"!!^') }) + api.nvim_input_mouse('right', 'release', '', 2, 1, 0) + screen:expect({ any = vim.pesc('#!!^') }) + + api.nvim_input_mouse('right', 'press', '', 2, 10, 0) + screen:expect({ any = vim.pesc('"!*^') }) + api.nvim_input_mouse('right', 'release', '', 2, 10, 0) + screen:expect({ any = vim.pesc('#!*^') }) + + api.nvim_input_mouse('right', 'press', '', 2, 1, 57) + screen:expect({ any = vim.pesc('"Z!^') }) + api.nvim_input_mouse('right', 'release', '', 2, 1, 57) + screen:expect({ any = vim.pesc('#Z!^') }) + + api.nvim_input_mouse('right', 'press', '', 2, 10, 57) + screen:expect({ any = vim.pesc('"Z*^') }) + api.nvim_input_mouse('right', 'release', '', 2, 10, 57) + screen:expect({ any = vim.pesc('#Z*^') }) + end) end) describe('with a split window and other buffer', function()