Merge pull request #39201 from tomtomjhj/textoff-showbreak-crash

fix(smoothscroll): crash when resizing to textoff with showbreak
This commit is contained in:
zeertzjq
2026-04-20 09:45:12 +08:00
committed by GitHub
3 changed files with 58 additions and 1 deletions

View File

@@ -269,7 +269,7 @@ CharSize charsize_regular(CharsizeArg *csarg, char *const cur, colnr_T const vco
if (max_head_vcol == 0 || vcol + size + added < max_head_vcol) {
head += cnt * head_mid;
} else if (max_head_vcol > vcol + head_prev + prev_rem) {
} else if (width2 > 0 && max_head_vcol > vcol + head_prev + prev_rem) {
head += (max_head_vcol - (vcol + head_prev + prev_rem)
+ width2 - 1) / width2 * head_mid;
} else if (max_head_vcol < 0) {

View File

@@ -1127,6 +1127,24 @@ describe('smoothscroll', function()
screen:expect(screen_l_top)
end)
-- oldtest: Test_smoothscroll_textoff_showbreak()
it('does not crash when resizing to textoff with showbreak', function()
exec([[
set noswapfile scrolloff=0
call setline(1, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
set number wrap smoothscroll showbreak=>
vsplit
let textoff = getwininfo(win_getid())[0].textoff
execute "normal! 0\<C-E>"
redraw
execute 'vertical resize' textoff
redraw
]])
assert_alive()
end)
it('works with virt_lines above and below', function()
screen:try_resize(55, 7)
exec([=[

View File

@@ -1443,4 +1443,43 @@ func Test_smoothscroll_listchars_eol()
bwipe!
endfunc
" Resizing to "textoff" after 'smoothscroll' skips part of a wrapped line must
" not crash.
func Test_smoothscroll_textoff_showbreak()
CheckOption smoothscroll
CheckRunVimInTerminal
let donefile = 'XTest_crash_textoff_showbreak_done'
defer delete(donefile)
let lines =<< trim END
set noswapfile
set scrolloff=0
set lines=12 columns=40
call setline(1, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
set number wrap smoothscroll showbreak=>
vsplit
let textoff = getwininfo(win_getid())[0].textoff
execute "normal! 0\<C-E>"
redraw
execute 'vertical resize' textoff
redraw
call writefile(['done'], 'XTest_crash_textoff_showbreak_done')
END
call writefile(lines, 'XTest_crash_textoff_showbreak', 'D')
let buf = 0
let buf = term_start([GetVimProg(), '--clean'], #{term_rows: 24, term_cols: 80})
call TermWait(buf, 200)
call term_sendkeys(buf, ":source XTest_crash_textoff_showbreak\<CR>")
call WaitForAssert({-> assert_true(filereadable(donefile))})
let status = term_getstatus(buf)
call assert_equal('running', status)
call assert_true(filereadable(donefile))
call StopVimInTerminal(buf)
endfunc
" vim: shiftwidth=2 sts=2 expandtab