fix: screenchar()/screenstring() with multigrid #32494

Problem:
- When multigrid is enabled, screenchar()/screenstring() functions return wrong
  results. See https://github.com/neovide/neovide/issues/2569
- `screenstring()` executed via RPC in child Nvim process, doesn't recognize
  floating windows.

Solution:
In ui_comp_get_grid_at_coord(), also iterate window grids.
This commit is contained in:
fredizzimo
2025-04-26 23:39:12 +03:00
committed by GitHub
parent dd18ab1691
commit 1999c4cdc1
2 changed files with 52 additions and 33 deletions

View File

@@ -333,6 +333,14 @@ ScreenGrid *ui_comp_get_grid_at_coord(int row, int col)
return grid; return grid;
} }
} }
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
ScreenGrid *grid = &wp->w_grid_alloc;
if (row >= grid->comp_row && row < grid->comp_row + grid->rows
&& col >= grid->comp_col && col < grid->comp_col + grid->cols) {
return grid;
}
}
return &default_grid; return &default_grid;
} }

View File

@@ -1,5 +1,6 @@
local t = require('test.testutil') local t = require('test.testutil')
local n = require('test.functional.testnvim')() local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local clear, eq, neq = n.clear, t.eq, t.neq local clear, eq, neq = n.clear, t.eq, t.neq
local command, api, fn = n.command, n.api, n.fn local command, api, fn = n.command, n.api, n.fn
@@ -30,8 +31,10 @@ local setup_floating_windows = function()
end end
describe('screenchar() and family respect floating windows', function() describe('screenchar() and family respect floating windows', function()
local function with_ext_multigrid(multigrid)
before_each(function() before_each(function()
clear() clear()
Screen.new(40, 7, { ext_multigrid = multigrid })
-- These commands result into visible text `aabc`. -- These commands result into visible text `aabc`.
-- `aab` - from floating windows, `c` - from text in regular window. -- `aab` - from floating windows, `c` - from text in regular window.
api.nvim_buf_set_lines(0, 0, -1, true, { 'cccc' }) api.nvim_buf_set_lines(0, 0, -1, true, { 'cccc' })
@@ -68,4 +71,12 @@ describe('screenchar() and family respect floating windows', function()
eq('b', fn.screenstring(1, 3)) eq('b', fn.screenstring(1, 3))
eq('c', fn.screenstring(1, 4)) eq('c', fn.screenstring(1, 4))
end) end)
end
describe('with ext_multigrid', function()
with_ext_multigrid(true)
end)
describe('without ext_multigrid', function()
with_ext_multigrid(false)
end)
end) end)