Merge pull request #23194 from zeertzjq/vim-9.0.1141

vim-patch:9.0.1141: 'cursorcolumn' and 'colorcolumn' wrong after concealing
This commit is contained in:
zeertzjq 2023-04-19 18:21:43 +08:00 committed by GitHub
commit ccc939ec10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 591 additions and 106 deletions

View File

@ -2947,6 +2947,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange,
}
wlv.boguscols = 0;
wlv.vcol_off = 0;
wlv.row++;
// When not wrapping and finished diff lines, or when displayed

View File

@ -1,97 +0,0 @@
-- Tests for correct display (cursor column position) with +conceal and
-- tabulators.
local helpers = require('test.functional.helpers')(after_each)
local feed, insert, clear, feed_command =
helpers.feed, helpers.insert, helpers.clear, helpers.feed_command
local expect_pos = function(row, col)
return helpers.eq({row, col}, helpers.eval('[screenrow(), screencol()]'))
end
describe('cursor and column position with conceal and tabulators', function()
setup(clear)
-- luacheck: ignore 621 (Indentation)
it('are working', function()
insert([[
start:
.concealed. text
|concealed| text
.concealed. text
|concealed| text
.a. .b. .c. .d.
|a| |b| |c| |d|]])
-- Conceal settings.
feed_command('set conceallevel=2')
feed_command('set concealcursor=nc')
feed_command('syntax match test /|/ conceal')
-- Start test.
feed_command('/^start:')
feed('ztj')
expect_pos(2, 1)
-- We should end up in the same column when running these commands on the
-- two lines.
feed('ft')
expect_pos(2, 17)
feed('$')
expect_pos(2, 20)
feed('0j')
expect_pos(3, 1)
feed('ft')
expect_pos(3, 17)
feed('$')
expect_pos(3, 20)
feed('j0j')
expect_pos(5, 8)
-- Same for next test block.
feed('ft')
expect_pos(5, 25)
feed('$')
expect_pos(5, 28)
feed('0j')
expect_pos(6, 8)
feed('ft')
expect_pos(6, 25)
feed('$')
expect_pos(6, 28)
feed('0j0j')
expect_pos(8, 1)
-- And check W with multiple tabs and conceals in a line.
feed('W')
expect_pos(8, 9)
feed('W')
expect_pos(8, 17)
feed('W')
expect_pos(8, 25)
feed('$')
expect_pos(8, 27)
feed('0j')
expect_pos(9, 1)
feed('W')
expect_pos(9, 9)
feed('W')
expect_pos(9, 17)
feed('W')
expect_pos(9, 25)
feed('$')
expect_pos(9, 26)
feed_command('set lbr')
feed('$')
expect_pos(9, 26)
feed_command('set list listchars=tab:>-')
feed('0')
expect_pos(9, 1)
feed('W')
expect_pos(9, 9)
feed('W')
expect_pos(9, 17)
feed('W')
expect_pos(9, 25)
feed('$')
expect_pos(9, 26)
end)
end)

View File

@ -0,0 +1,554 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local command = helpers.command
local exec = helpers.exec
local feed = helpers.feed
local expect_pos = function(row, col)
return helpers.eq({row, col}, helpers.eval('[screenrow(), screencol()]'))
end
describe('Conceal', function()
before_each(function()
clear()
command('set nohlsearch')
end)
-- oldtest: Test_conceal_two_windows()
it('works', function()
local screen = Screen.new(75, 12)
screen:set_default_attr_ids({
[0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
[1] = {bold = true, reverse = true}, -- StatusLine
[2] = {reverse = true}, -- StatusLineNC, IncSearch
[3] = {bold = true}, -- ModeMsg
})
screen:attach()
exec([[
let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"]
call setline(1, lines)
syntax match test /|hidden|/ conceal
set conceallevel=2
set concealcursor=
exe "normal /here\r"
new
call setline(1, lines)
call setline(4, "Second window")
syntax match test /|hidden|/ conceal
set conceallevel=2
set concealcursor=nc
exe "normal /here\r"
]])
-- Check that cursor line is concealed
screen:expect([[
one one one one one |
two ^here |
three three |
Second window |
{0:~ }|
{1:[No Name] [+] }|
one one one one one |
two here |
three three |
{0:~ }|
{2:[No Name] [+] }|
/here |
]])
-- Check that with concealed text vertical cursor movement is correct.
feed('k')
screen:expect([[
one one one o^ne one |
two here |
three three |
Second window |
{0:~ }|
{1:[No Name] [+] }|
one one one one one |
two here |
three three |
{0:~ }|
{2:[No Name] [+] }|
/here |
]])
-- Check that with cursor line is not concealed
feed('j')
command('set concealcursor=')
screen:expect([[
one one one one one |
two |hidden| ^here |
three three |
Second window |
{0:~ }|
{1:[No Name] [+] }|
one one one one one |
two here |
three three |
{0:~ }|
{2:[No Name] [+] }|
/here |
]])
-- Check that with cursor line is not concealed when moving cursor down
feed('j')
screen:expect([[
one one one one one |
two here |
three |hidden^| three |
Second window |
{0:~ }|
{1:[No Name] [+] }|
one one one one one |
two here |
three three |
{0:~ }|
{2:[No Name] [+] }|
/here |
]])
-- Check that with cursor line is not concealed when switching windows
feed('<C-W><C-W>')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| ^here |
three three |
{0:~ }|
{1:[No Name] [+] }|
/here |
]])
-- Check that with cursor line is only concealed in Normal mode
command('set concealcursor=n')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two ^here |
three three |
{0:~ }|
{1:[No Name] [+] }|
/here |
]])
feed('a')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h^ere |
three three |
{0:~ }|
{1:[No Name] [+] }|
{3:-- INSERT --} |
]])
feed('<Esc>/e')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h{2:e}re |
three three |
{0:~ }|
{1:[No Name] [+] }|
/e^ |
]])
feed('<Esc>v')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| ^here |
three three |
{0:~ }|
{1:[No Name] [+] }|
{3:-- VISUAL --} |
]])
feed('<Esc>')
-- Check that with cursor line is only concealed in Insert mode
command('set concealcursor=i')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| ^here |
three three |
{0:~ }|
{1:[No Name] [+] }|
|
]])
feed('a')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two h^ere |
three three |
{0:~ }|
{1:[No Name] [+] }|
{3:-- INSERT --} |
]])
feed('<Esc>/e')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h{2:e}re |
three three |
{0:~ }|
{1:[No Name] [+] }|
/e^ |
]])
feed('<Esc>v')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| ^here |
three three |
{0:~ }|
{1:[No Name] [+] }|
{3:-- VISUAL --} |
]])
feed('<Esc>')
-- Check that with cursor line is only concealed in Visual mode
command('set concealcursor=v')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| ^here |
three three |
{0:~ }|
{1:[No Name] [+] }|
|
]])
feed('a')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h^ere |
three three |
{0:~ }|
{1:[No Name] [+] }|
{3:-- INSERT --} |
]])
feed('<Esc>/e')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h{2:e}re |
three three |
{0:~ }|
{1:[No Name] [+] }|
/e^ |
]])
feed('<Esc>v')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two ^here |
three three |
{0:~ }|
{1:[No Name] [+] }|
{3:-- VISUAL --} |
]])
feed('<Esc>')
-- Check moving the cursor while in insert mode.
command('set concealcursor=')
feed('a')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two |hidden| h^ere |
three three |
{0:~ }|
{1:[No Name] [+] }|
{3:-- INSERT --} |
]])
feed('<Down>')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two here |
three |hidden|^ three |
{0:~ }|
{1:[No Name] [+] }|
{3:-- INSERT --} |
]])
feed('<Esc>')
-- Check the "o" command
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two here |
three |hidden^| three |
{0:~ }|
{1:[No Name] [+] }|
|
]])
feed('o')
screen:expect([[
one one one one one |
two here |
three three |
Second window |
{0:~ }|
{2:[No Name] [+] }|
one one one one one |
two here |
three three |
^ |
{1:[No Name] [+] }|
{3:-- INSERT --} |
]])
feed('<Esc>')
end)
-- oldtest: Test_conceal_with_cursorcolumn()
it('CursorColumn and ColorColumn on wrapped line', function()
local screen = Screen.new(40, 10)
screen:set_default_attr_ids({
[0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
[1] = {background = Screen.colors.Grey90}, -- CursorColumn
[2] = {background = Screen.colors.LightRed}, -- ColorColumn
})
screen:attach()
-- Check that cursorcolumn and colorcolumn don't get broken in presence of
-- wrapped lines containing concealed text
-- luacheck: push ignore 613 (trailing whitespace in a string)
exec([[
let lines = ["one one one |hidden| one one one one one one one one",
\ "two two two two |hidden| here two two",
\ "three |hidden| three three three three three three three three"]
call setline(1, lines)
set wrap linebreak
set showbreak=\ >>>\
syntax match test /|hidden|/ conceal
set conceallevel=2
set concealcursor=
exe "normal /here\r"
set cursorcolumn
set colorcolumn=50
]])
-- luacheck: pop
screen:expect([[
one one one one one one {1:o}ne |
{0: >>> }one {2:o}ne one one |
two two two two |hidden| ^here two two |
three three three three {1:t}hree |
{0: >>> }thre{2:e} three three three |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
/here |
]])
-- move cursor to the end of line (the cursor jumps to the next screen line)
feed('$')
screen:expect([[
one one one one one one one |
{0: >>> }one {2:o}ne one one |
two two two two |hidden| here two tw^o |
three three three three three |
{0: >>> }thre{2:e} three three three |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
/here |
]])
end)
-- oldtest: Test_conceal_resize_term()
it('resize editor', function()
local screen = Screen.new(75, 6)
screen:set_default_attr_ids({
[0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
[1] = {foreground = Screen.colors.Blue}, -- Comment
})
screen:attach()
exec([[
call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed')
setl cocu=n cole=3
syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends
normal fb
]])
screen:expect([[
one two three four five, the ^backticks should be concealed |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
|
]])
screen:try_resize(75, 7)
screen:expect([[
one two three four five, the ^backticks should be concealed |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
|
]])
end)
-- Tests for correct display (cursor column position) with +conceal and tabulators.
-- oldtest: Test_conceal_cursor_pos()
it('cursor and column position with conceal and tabulators', function()
exec([[
let l = ['start:', '.concealed. text', "|concealed|\ttext"]
let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", '']
let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"]
call append(0, l)
call cursor(1, 1)
" Conceal settings.
set conceallevel=2
set concealcursor=nc
syntax match test /|/ conceal
]])
feed('ztj')
expect_pos(2, 1)
-- We should end up in the same column when running these commands on the
-- two lines.
feed('ft')
expect_pos(2, 17)
feed('$')
expect_pos(2, 20)
feed('0j')
expect_pos(3, 1)
feed('ft')
expect_pos(3, 17)
feed('$')
expect_pos(3, 20)
feed('j0j')
expect_pos(5, 8)
-- Same for next test block.
feed('ft')
expect_pos(5, 25)
feed('$')
expect_pos(5, 28)
feed('0j')
expect_pos(6, 8)
feed('ft')
expect_pos(6, 25)
feed('$')
expect_pos(6, 28)
feed('0j0j')
expect_pos(8, 1)
-- And check W with multiple tabs and conceals in a line.
feed('W')
expect_pos(8, 9)
feed('W')
expect_pos(8, 17)
feed('W')
expect_pos(8, 25)
feed('$')
expect_pos(8, 27)
feed('0j')
expect_pos(9, 1)
feed('W')
expect_pos(9, 9)
feed('W')
expect_pos(9, 17)
feed('W')
expect_pos(9, 25)
feed('$')
expect_pos(9, 26)
command('set lbr')
feed('$')
expect_pos(9, 26)
command('set list listchars=tab:>-')
feed('0')
expect_pos(9, 1)
feed('W')
expect_pos(9, 9)
feed('W')
expect_pos(9, 17)
feed('W')
expect_pos(9, 25)
feed('$')
expect_pos(9, 26)
end)
end)

View File

@ -24,7 +24,7 @@ func Test_conceal_two_windows()
exe "normal /here\r"
[CODE]
call writefile(code, 'XTest_conceal')
call writefile(code, 'XTest_conceal', 'D')
" Check that cursor line is concealed
let buf = RunVimInTerminal('-S XTest_conceal', {})
call VerifyScreenDump(buf, 'Test_conceal_two_windows_01', {})
@ -106,7 +106,6 @@ func Test_conceal_two_windows()
" clean up
call StopVimInTerminal(buf)
call delete('XTest_conceal')
endfunc
func Test_conceal_with_cursorline()
@ -123,7 +122,7 @@ func Test_conceal_with_cursorline()
normal M
[CODE]
call writefile(code, 'XTest_conceal_cul')
call writefile(code, 'XTest_conceal_cul', 'D')
let buf = RunVimInTerminal('-S XTest_conceal_cul', {})
call VerifyScreenDump(buf, 'Test_conceal_cul_01', {})
@ -135,7 +134,38 @@ func Test_conceal_with_cursorline()
" clean up
call StopVimInTerminal(buf)
call delete('XTest_conceal_cul')
endfunc
func Test_conceal_with_cursorcolumn()
CheckScreendump
" Check that cursorcolumn and colorcolumn don't get broken in presence of
" wrapped lines containing concealed text
let code =<< trim [CODE]
let lines = ["one one one |hidden| one one one one one one one one",
\ "two two two two |hidden| here two two",
\ "three |hidden| three three three three three three three three"]
call setline(1, lines)
set wrap linebreak
set showbreak=\ >>>\
syntax match test /|hidden|/ conceal
set conceallevel=2
set concealcursor=
exe "normal /here\r"
set cursorcolumn
set colorcolumn=50
[CODE]
call writefile(code, 'XTest_conceal_cuc', 'D')
let buf = RunVimInTerminal('-S XTest_conceal_cuc', {'rows': 10, 'cols': 40})
call VerifyScreenDump(buf, 'Test_conceal_cuc_01', {})
" move cursor to the end of line (the cursor jumps to the next screen line)
call term_sendkeys(buf, "$")
call VerifyScreenDump(buf, 'Test_conceal_cuc_02', {})
" clean up
call StopVimInTerminal(buf)
endfunc
func Test_conceal_resize_term()
@ -147,17 +177,15 @@ func Test_conceal_resize_term()
syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends
normal fb
[CODE]
call writefile(code, 'XTest_conceal_resize')
call writefile(code, 'XTest_conceal_resize', 'D')
let buf = RunVimInTerminal('-S XTest_conceal_resize', {'rows': 6})
call VerifyScreenDump(buf, 'Test_conceal_resize_01', {})
call win_execute(buf->win_findbuf()[0], 'wincmd +')
call TermWait(buf)
call VerifyScreenDump(buf, 'Test_conceal_resize_02', {})
" clean up
call StopVimInTerminal(buf)
call delete('XTest_conceal_resize')
endfunc
" Tests for correct display (cursor column position) with +conceal and
@ -245,7 +273,7 @@ func Test_conceal_cursor_pos()
:q!
[CODE]
call writefile(code, 'XTest_conceal_curpos')
call writefile(code, 'XTest_conceal_curpos', 'D')
if RunVim([], [], '-s XTest_conceal_curpos')
call assert_equal([
@ -256,7 +284,6 @@ func Test_conceal_cursor_pos()
endif
call delete('Xconceal_curpos.out')
call delete('XTest_conceal_curpos')
endfunc
func Test_conceal_eol()