commit f02484118c85190afccdce22ccec578452269263
parent 0ab0cdb2dabc551f836851aa85d06e927c42d92a
Author: bfredl <bjorn.linse@gmail.com>
Date: Wed, 30 Apr 2025 11:49:47 +0200
fix(ui): correct condition for "wrap" flag in a floating grid
In a floating window grid, "wrap" flag should not
be set when vertical borders are used, as the the wrapped
text will be broken up by border chars.
fixes #33719
Diffstat:
3 files changed, 167 insertions(+), 3 deletions(-)
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
@@ -3026,12 +3026,12 @@ end_check:
|| (wp->w_p_list && wp->w_p_lcs_chars.eol != NUL && lcs_eol_todo)
|| (wlv.n_extra != 0 && (wlv.sc_extra != NUL || *wlv.p_extra != NUL))
|| (may_have_inline_virt && has_more_inline_virt(&wlv, ptr - line)))) {
+ int grid_width = wp->w_grid.target->cols;
const bool wrap = is_wrapped // Wrapping enabled (not a folded line).
&& wlv.filler_todo <= 0 // Not drawing diff filler lines.
&& lcs_eol_todo // Haven't printed the lcs_eol character.
&& wlv.row != endrow - 1 // Not the last line being displayed.
- && (view_width == Columns // Window spans the width of the screen,
- || wp->w_grid_alloc.chars) // or has dedicated grid.
+ && view_width == grid_width // Window spans the width of its grid.
&& !wp->w_p_rl; // Not right-to-left.
int draw_col = wlv.col - wlv.boguscols;
diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua
@@ -2918,6 +2918,169 @@ describe('float window', function()
end
end)
+ it("doesn't wrap with vertical border", function()
+ screen:try_resize(40,10)
+ local buf = api.nvim_create_buf(false, false)
+ api.nvim_open_win(buf, false, {relative='editor', width=9, height=3, row=0, col=5, border="double"})
+ -- make sure text is drawn after border
+ if multigrid then
+ screen:expect {grid = [[
+ ## grid 1
+ [2:----------------------------------------]|*9
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|*8
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔═════════╗}|
+ {5:║}{1: }{5:║}|
+ {5:║}{2:~ }{5:║}|*2
+ {5:╚═════════╝}|
+ ]],
+ win_pos = {
+ [2] = {
+ height = 9,
+ startcol = 0,
+ startrow = 0,
+ width = 40,
+ win = 1000
+ }
+ },
+ float_pos = {
+ [4] = {1001, "NW", 1, 0, 5, true, 50, 1, 0, 5};
+ },
+ win_viewport = {
+ [2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ },
+ win_viewport_margins = {
+ [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 };
+ [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 };
+ },
+ }
+ else
+ screen:expect([[
+ ^ {5:╔═════════╗} |
+ {0:~ }{5:║}{1: }{5:║}{0: }|
+ {0:~ }{5:║}{2:~ }{5:║}{0: }|*2
+ {0:~ }{5:╚═════════╝}{0: }|
+ {0:~ }|*4
+ |
+ ]])
+ end
+ api.nvim_buf_set_lines(buf, 0, -1, true, {'aaa long line', 'abb acc '})
+ if multigrid then
+ screen:expect {
+ grid = [[
+ ## grid 1
+ [2:----------------------------------------]|*9
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|*8
+ ## grid 3
+ |
+ ## grid 4
+ {5:╔═════════╗}|
+ {5:║}{1:aaa long }{5:║}|
+ {5:║}{1:line }{5:║}|
+ {5:║}{1:abb acc }{5:║}|
+ {5:╚═════════╝}|
+ ]],
+ win_pos = {
+ [2] = {
+ height = 9,
+ startcol = 0,
+ startrow = 0,
+ width = 40,
+ win = 1000
+ }
+ },
+ float_pos = {
+ [4] = {1001, "NW", 1, 0, 5, true, 50, 1, 0, 5};
+ },
+ win_viewport = {
+ [2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ },
+ win_viewport_margins = {
+ [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
+ [4] = { bottom = 1, left = 1, right = 1, top = 1, win = 1001 }
+ },
+ condition = function()
+ for i = 1,5 do
+ eq(false, screen._grids[4].rows[i].wrap, i)
+ end
+ end
+ }
+ else
+ screen:expect([[
+ ^ {5:╔═════════╗} |
+ {0:~ }{5:║}{1:aaa long }{5:║}{0: }|
+ {0:~ }{5:║}{1:line }{5:║}{0: }|
+ {0:~ }{5:║}{1:abb acc }{5:║}{0: }|
+ {0:~ }{5:╚═════════╝}{0: }|
+ {0:~ }|*4
+ |
+ ]])
+ end
+ end)
+
+ it("does wrap without vertical border", function()
+ screen:try_resize(40,10)
+ local buf = api.nvim_create_buf(false, false)
+ api.nvim_buf_set_lines(buf, 0, -1, true, {'aaa long line', 'abb acc '})
+ api.nvim_open_win(buf, false, {relative='editor', width=9, height=3, row=0, col=5})
+ if multigrid then
+ screen:expect {
+ grid = [[
+ ## grid 1
+ [2:----------------------------------------]|*9
+ [3:----------------------------------------]|
+ ## grid 2
+ ^ |
+ {0:~ }|*8
+ ## grid 3
+ |
+ ## grid 4
+ {1:aaa long }|
+ {1:line }|
+ {1:abb acc }|
+ ]],
+ win_pos = {
+ [2] = { height = 9, startcol = 0, startrow = 0, width = 40, win = 1000
+ }
+ },
+ float_pos = {
+ [4] = {1001, "NW", 1, 0, 5, true, 50, 1, 0, 5};
+ },
+ win_viewport = {
+ [2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
+ [4] = {win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0};
+ },
+ win_viewport_margins = {
+ [2] = { bottom = 0, left = 0, right = 0, top = 0, win = 1000 },
+ [4] = { bottom = 0, left = 0, right = 0, top = 0, win = 1001 }
+ },
+ condition = function()
+ for i = 1,3 do
+ eq(i == 1, screen._grids[4].rows[i].wrap, i)
+ end
+ end,
+ }
+ else
+ screen:expect([[
+ ^ {1:aaa long } |
+ {0:~ }{1:line }{0: }|
+ {0:~ }{1:abb acc }{0: }|
+ {0:~ }|*6
+ |
+ ]])
+ end
+ end)
+
it('show ruler of current floating window', function()
command 'set ruler'
local buf = api.nvim_create_buf(false, false)
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
@@ -1230,12 +1230,13 @@ end
--- @param row integer
--- @param col integer
--- @param items integer[][]
-function Screen:_handle_grid_line(grid, row, col, items)
+function Screen:_handle_grid_line(grid, row, col, items, wrap)
assert(self._options.ext_linegrid)
assert(#items > 0)
local line = self._grids[grid].rows[row + 1]
local colpos = col + 1
local hl_id = 0
+ line.wrap = wrap
for _, item in ipairs(items) do
local text, hl_id_cell, count = item[1], item[2], item[3]
if hl_id_cell ~= nil then