mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.1.0180: Cursor pos wrong when double-width chars are concealed (#27862)
Problem: Cursor pos wrong when double-width chars are concealed.
Solution: Advance one more virtual column for a double-width char.
Run some tests with both 'wrap' and 'nowrap' (zeertzjq).
closes: vim/vim#14197
010e1539d6
This commit is contained in:
parent
ca7dd33fa7
commit
60491466f9
@ -2403,6 +2403,13 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
|
|||||||
} else {
|
} else {
|
||||||
mb_schar = schar_from_ascii(' ');
|
mb_schar = schar_from_ascii(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (utf_char2cells(mb_c) > 1) {
|
||||||
|
// When the first char to be concealed is double-width,
|
||||||
|
// need to advance one more virtual column.
|
||||||
|
wlv.n_extra++;
|
||||||
|
}
|
||||||
|
|
||||||
mb_c = schar_get_first_codepoint(mb_schar);
|
mb_c = schar_get_first_codepoint(mb_schar);
|
||||||
|
|
||||||
prev_syntax_id = syntax_seqnr;
|
prev_syntax_id = syntax_seqnr;
|
||||||
@ -2739,11 +2746,21 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
|
|||||||
wlv.off++;
|
wlv.off++;
|
||||||
wlv.col++;
|
wlv.col++;
|
||||||
} else if (wp->w_p_cole > 0 && is_concealing) {
|
} else if (wp->w_p_cole > 0 && is_concealing) {
|
||||||
|
bool concealed_wide = utf_char2cells(mb_c) > 1;
|
||||||
|
|
||||||
wlv.skip_cells--;
|
wlv.skip_cells--;
|
||||||
wlv.vcol_off_co++;
|
wlv.vcol_off_co++;
|
||||||
|
if (concealed_wide) {
|
||||||
|
// When a double-width char is concealed,
|
||||||
|
// need to advance one more virtual column.
|
||||||
|
wlv.vcol++;
|
||||||
|
wlv.vcol_off_co++;
|
||||||
|
}
|
||||||
|
|
||||||
if (wlv.n_extra > 0) {
|
if (wlv.n_extra > 0) {
|
||||||
wlv.vcol_off_co += wlv.n_extra;
|
wlv.vcol_off_co += wlv.n_extra;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_wrapped) {
|
if (is_wrapped) {
|
||||||
// Special voodoo required if 'wrap' is on.
|
// Special voodoo required if 'wrap' is on.
|
||||||
//
|
//
|
||||||
@ -2764,7 +2781,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
|
|||||||
wlv.n_attr = 0;
|
wlv.n_attr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (utf_char2cells(mb_c) > 1) {
|
if (concealed_wide) {
|
||||||
// Need to fill two screen columns.
|
// Need to fill two screen columns.
|
||||||
wlv.boguscols++;
|
wlv.boguscols++;
|
||||||
wlv.col++;
|
wlv.col++;
|
||||||
|
@ -4,6 +4,7 @@ local clear = helpers.clear
|
|||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
local exec = helpers.exec
|
local exec = helpers.exec
|
||||||
local feed = helpers.feed
|
local feed = helpers.feed
|
||||||
|
local api = helpers.api
|
||||||
|
|
||||||
local expect_pos = function(row, col)
|
local expect_pos = function(row, col)
|
||||||
return helpers.eq({ row, col }, helpers.eval('[screenrow(), screencol()]'))
|
return helpers.eq({ row, col }, helpers.eval('[screenrow(), screencol()]'))
|
||||||
@ -633,13 +634,13 @@ describe('Conceal', function()
|
|||||||
expect_pos(9, 26)
|
expect_pos(9, 26)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- oldtest: Test_conceal_virtualedit_after_eol()
|
local function test_conceal_virtualedit_after_eol(wrap)
|
||||||
it('cursor drawn at correct column with virtualedit', function()
|
local screen = Screen.new(60, 3)
|
||||||
local screen = Screen.new(75, 3)
|
|
||||||
screen:set_default_attr_ids({
|
screen:set_default_attr_ids({
|
||||||
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
|
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
|
||||||
})
|
})
|
||||||
screen:attach()
|
screen:attach()
|
||||||
|
api.nvim_set_option_value('wrap', wrap, {})
|
||||||
exec([[
|
exec([[
|
||||||
call setline(1, 'abcdefgh|hidden|ijklmnpop')
|
call setline(1, 'abcdefgh|hidden|ijklmnpop')
|
||||||
syntax match test /|hidden|/ conceal
|
syntax match test /|hidden|/ conceal
|
||||||
@ -647,43 +648,53 @@ describe('Conceal', function()
|
|||||||
normal! $
|
normal! $
|
||||||
]])
|
]])
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
abcdefghijklmnpo^p |
|
abcdefghijklmnpo^p |
|
||||||
{0:~ }|
|
{0:~ }|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
feed('l')
|
feed('l')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
abcdefghijklmnpop^ |
|
abcdefghijklmnpop^ |
|
||||||
{0:~ }|
|
{0:~ }|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
feed('l')
|
feed('l')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
abcdefghijklmnpop ^ |
|
abcdefghijklmnpop ^ |
|
||||||
{0:~ }|
|
{0:~ }|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
feed('l')
|
feed('l')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
abcdefghijklmnpop ^ |
|
abcdefghijklmnpop ^ |
|
||||||
{0:~ }|
|
{0:~ }|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
feed('rr')
|
feed('rr')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
abcdefghijklmnpop ^r |
|
abcdefghijklmnpop ^r |
|
||||||
{0:~ }|
|
{0:~ }|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
|
end
|
||||||
|
|
||||||
|
-- oldtest: Test_conceal_virtualedit_after_eol()
|
||||||
|
describe('cursor drawn at correct column with virtualedit', function()
|
||||||
|
it('with wrapping', function()
|
||||||
|
test_conceal_virtualedit_after_eol(true)
|
||||||
|
end)
|
||||||
|
it('without wrapping', function()
|
||||||
|
test_conceal_virtualedit_after_eol(false)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- oldtest: Test_conceal_virtualedit_after_eol_rightleft()
|
local function test_conceal_virtualedit_after_eol_rightleft(wrap)
|
||||||
it('cursor drawn correctly with virtualedit and rightleft', function()
|
local screen = Screen.new(60, 3)
|
||||||
local screen = Screen.new(75, 3)
|
|
||||||
screen:set_default_attr_ids({
|
screen:set_default_attr_ids({
|
||||||
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
|
[0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
|
||||||
})
|
})
|
||||||
screen:attach()
|
screen:attach()
|
||||||
|
api.nvim_set_option_value('wrap', wrap, {})
|
||||||
exec([[
|
exec([[
|
||||||
call setline(1, 'abcdefgh|hidden|ijklmnpop')
|
call setline(1, 'abcdefgh|hidden|ijklmnpop')
|
||||||
syntax match test /|hidden|/ conceal
|
syntax match test /|hidden|/ conceal
|
||||||
@ -691,33 +702,141 @@ describe('Conceal', function()
|
|||||||
normal! $
|
normal! $
|
||||||
]])
|
]])
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^popnmlkjihgfedcba|
|
^popnmlkjihgfedcba|
|
||||||
{0: ~}|
|
{0: ~}|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
feed('h')
|
feed('h')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^ popnmlkjihgfedcba|
|
^ popnmlkjihgfedcba|
|
||||||
{0: ~}|
|
{0: ~}|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
feed('h')
|
feed('h')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^ popnmlkjihgfedcba|
|
^ popnmlkjihgfedcba|
|
||||||
{0: ~}|
|
{0: ~}|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
feed('h')
|
feed('h')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^ popnmlkjihgfedcba|
|
^ popnmlkjihgfedcba|
|
||||||
{0: ~}|
|
{0: ~}|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
feed('rr')
|
feed('rr')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^r popnmlkjihgfedcba|
|
^r popnmlkjihgfedcba|
|
||||||
{0: ~}|
|
{0: ~}|
|
||||||
|
|
|
|
||||||
|
]])
|
||||||
|
end
|
||||||
|
|
||||||
|
-- oldtest: Test_conceal_virtualedit_after_eol_rightleft()
|
||||||
|
describe('cursor drawn correctly with virtualedit and rightleft', function()
|
||||||
|
it('with wrapping', function()
|
||||||
|
test_conceal_virtualedit_after_eol_rightleft(true)
|
||||||
|
end)
|
||||||
|
it('without wrapping', function()
|
||||||
|
test_conceal_virtualedit_after_eol_rightleft(false)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
local function test_conceal_double_width(wrap)
|
||||||
|
local screen = Screen.new(60, 4)
|
||||||
|
screen:set_default_attr_ids({
|
||||||
|
[0] = { bold = true, foreground = Screen.colors.Blue },
|
||||||
|
[1] = { background = Screen.colors.DarkGrey, foreground = Screen.colors.LightGrey },
|
||||||
|
[2] = { background = Screen.colors.LightRed },
|
||||||
|
})
|
||||||
|
screen:attach()
|
||||||
|
api.nvim_set_option_value('wrap', wrap, {})
|
||||||
|
exec([[
|
||||||
|
call setline(1, ['aaaaa口=口bbbbb口=口ccccc', 'foobar'])
|
||||||
|
syntax match test /口=口/ conceal cchar=β
|
||||||
|
set conceallevel=2 concealcursor=n colorcolumn=30
|
||||||
|
normal! $
|
||||||
|
]])
|
||||||
|
screen:expect([[
|
||||||
|
aaaaa{1:β}bbbbb{1:β}cccc^c {2: } |
|
||||||
|
foobar {2: } |
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('gM')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaa{1:β}bb^bbb{1:β}ccccc {2: } |
|
||||||
|
foobar {2: } |
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
command('set conceallevel=3')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaabb^bbbccccc {2: } |
|
||||||
|
foobar {2: } |
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('$')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaabbbbbcccc^c {2: } |
|
||||||
|
foobar {2: } |
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end
|
||||||
|
|
||||||
|
-- oldtest: Test_conceal_double_width()
|
||||||
|
describe('cursor drawn correctly when double-width chars are concealed', function()
|
||||||
|
it('with wrapping', function()
|
||||||
|
test_conceal_double_width(true)
|
||||||
|
end)
|
||||||
|
it('without wrapping', function()
|
||||||
|
test_conceal_double_width(false)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- oldtest: Test_conceal_double_width_wrap()
|
||||||
|
it('line wraps correctly when double-width chars are concealed', function()
|
||||||
|
local screen = Screen.new(20, 4)
|
||||||
|
screen:set_default_attr_ids({
|
||||||
|
[0] = { bold = true, foreground = Screen.colors.Blue },
|
||||||
|
[1] = { background = Screen.colors.DarkGrey, foreground = Screen.colors.LightGrey },
|
||||||
|
[2] = { background = Screen.colors.LightRed },
|
||||||
|
})
|
||||||
|
screen:attach()
|
||||||
|
exec([[
|
||||||
|
call setline(1, 'aaaaaaaaaa口=口bbbbbbbbbb口=口cccccccccc')
|
||||||
|
syntax match test /口=口/ conceal cchar=β
|
||||||
|
set conceallevel=2 concealcursor=n
|
||||||
|
normal! $
|
||||||
|
]])
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaa{1:β}bbbbb |
|
||||||
|
bbbbb{1:β}ccccccccc^c |
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('gM')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaa{1:β}bbbbb |
|
||||||
|
^bbbbb{1:β}cccccccccc |
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
command('set conceallevel=3')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaabbbbb |
|
||||||
|
^bbbbbcccccccccc |
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed('$')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaabbbbb |
|
||||||
|
bbbbbccccccccc^c |
|
||||||
|
{0:~ }|
|
||||||
|
|
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
@ -439,7 +439,7 @@ func Test_conceal_mouse_click()
|
|||||||
call Ntest_setmouse(1, 19)
|
call Ntest_setmouse(1, 19)
|
||||||
call feedkeys("\<LeftMouse>", "tx")
|
call feedkeys("\<LeftMouse>", "tx")
|
||||||
call assert_equal([0, 1, 23, 0, 23], getcurpos())
|
call assert_equal([0, 1, 23, 0, 23], getcurpos())
|
||||||
" click after end of line puts cursor there without 'virtualedit'
|
" click after end of line puts cursor there with 'virtualedit'
|
||||||
call Ntest_setmouse(1, 20)
|
call Ntest_setmouse(1, 20)
|
||||||
call feedkeys("\<LeftMouse>", "tx")
|
call feedkeys("\<LeftMouse>", "tx")
|
||||||
call assert_equal([0, 1, 24, 0, 24], getcurpos())
|
call assert_equal([0, 1, 24, 0, 24], getcurpos())
|
||||||
@ -462,10 +462,9 @@ endfunc
|
|||||||
|
|
||||||
" Test that cursor is drawn at the correct column when it is after end of the
|
" Test that cursor is drawn at the correct column when it is after end of the
|
||||||
" line with 'virtualedit' and concealing.
|
" line with 'virtualedit' and concealing.
|
||||||
func Test_conceal_virtualedit_after_eol()
|
func Run_test_conceal_virtualedit_after_eol(wrap)
|
||||||
CheckScreendump
|
let code =<< trim eval [CODE]
|
||||||
|
let &wrap = {a:wrap}
|
||||||
let code =<< trim [CODE]
|
|
||||||
call setline(1, 'abcdefgh|hidden|ijklmnpop')
|
call setline(1, 'abcdefgh|hidden|ijklmnpop')
|
||||||
syntax match test /|hidden|/ conceal
|
syntax match test /|hidden|/ conceal
|
||||||
set conceallevel=2 concealcursor=n virtualedit=all
|
set conceallevel=2 concealcursor=n virtualedit=all
|
||||||
@ -487,12 +486,17 @@ func Test_conceal_virtualedit_after_eol()
|
|||||||
call StopVimInTerminal(buf)
|
call StopVimInTerminal(buf)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Same as Test_conceal_virtualedit_after_eol(), but with 'rightleft' set.
|
func Test_conceal_virtualedit_after_eol()
|
||||||
func Test_conceal_virtualedit_after_eol_rightleft()
|
|
||||||
CheckFeature rightleft
|
|
||||||
CheckScreendump
|
CheckScreendump
|
||||||
|
|
||||||
let code =<< trim [CODE]
|
call Run_test_conceal_virtualedit_after_eol(1)
|
||||||
|
call Run_test_conceal_virtualedit_after_eol(0)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Same as Run_test_conceal_virtualedit_after_eol(), but with 'rightleft'.
|
||||||
|
func Run_test_conceal_virtualedit_after_eol_rightleft(wrap)
|
||||||
|
let code =<< trim eval [CODE]
|
||||||
|
let &wrap = {a:wrap}
|
||||||
call setline(1, 'abcdefgh|hidden|ijklmnpop')
|
call setline(1, 'abcdefgh|hidden|ijklmnpop')
|
||||||
syntax match test /|hidden|/ conceal
|
syntax match test /|hidden|/ conceal
|
||||||
set conceallevel=2 concealcursor=n virtualedit=all rightleft
|
set conceallevel=2 concealcursor=n virtualedit=all rightleft
|
||||||
@ -514,4 +518,66 @@ func Test_conceal_virtualedit_after_eol_rightleft()
|
|||||||
call StopVimInTerminal(buf)
|
call StopVimInTerminal(buf)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_conceal_virtualedit_after_eol_rightleft()
|
||||||
|
CheckFeature rightleft
|
||||||
|
CheckScreendump
|
||||||
|
|
||||||
|
call Run_test_conceal_virtualedit_after_eol_rightleft(1)
|
||||||
|
call Run_test_conceal_virtualedit_after_eol_rightleft(0)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test that cursor position is correct when double-width chars are concealed.
|
||||||
|
func Run_test_conceal_double_width(wrap)
|
||||||
|
let code =<< trim eval [CODE]
|
||||||
|
let &wrap = {a:wrap}
|
||||||
|
call setline(1, ['aaaaa口=口bbbbb口=口ccccc', 'foobar'])
|
||||||
|
syntax match test /口=口/ conceal cchar=β
|
||||||
|
set conceallevel=2 concealcursor=n colorcolumn=30
|
||||||
|
normal! $
|
||||||
|
[CODE]
|
||||||
|
call writefile(code, 'XTest_conceal_double_width', 'D')
|
||||||
|
let buf = RunVimInTerminal('-S XTest_conceal_double_width', {'rows': 4})
|
||||||
|
call VerifyScreenDump(buf, 'Test_conceal_double_width_1', {})
|
||||||
|
call term_sendkeys(buf, "gM")
|
||||||
|
call VerifyScreenDump(buf, 'Test_conceal_double_width_2', {})
|
||||||
|
call term_sendkeys(buf, ":set conceallevel=3\<CR>")
|
||||||
|
call VerifyScreenDump(buf, 'Test_conceal_double_width_3', {})
|
||||||
|
call term_sendkeys(buf, "$")
|
||||||
|
call VerifyScreenDump(buf, 'Test_conceal_double_width_4', {})
|
||||||
|
|
||||||
|
" clean up
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_conceal_double_width()
|
||||||
|
CheckScreendump
|
||||||
|
|
||||||
|
call Run_test_conceal_double_width(1)
|
||||||
|
call Run_test_conceal_double_width(0)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test that line wrapping is correct when double-width chars are concealed.
|
||||||
|
func Test_conceal_double_width_wrap()
|
||||||
|
CheckScreendump
|
||||||
|
|
||||||
|
let code =<< trim [CODE]
|
||||||
|
call setline(1, 'aaaaaaaaaa口=口bbbbbbbbbb口=口cccccccccc')
|
||||||
|
syntax match test /口=口/ conceal cchar=β
|
||||||
|
set conceallevel=2 concealcursor=n
|
||||||
|
normal! $
|
||||||
|
[CODE]
|
||||||
|
call writefile(code, 'XTest_conceal_double_width_wrap', 'D')
|
||||||
|
let buf = RunVimInTerminal('-S XTest_conceal_double_width_wrap', {'rows': 4, 'cols': 20})
|
||||||
|
call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_1', {})
|
||||||
|
call term_sendkeys(buf, "gM")
|
||||||
|
call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_2', {})
|
||||||
|
call term_sendkeys(buf, ":set conceallevel=3\<CR>")
|
||||||
|
call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_3', {})
|
||||||
|
call term_sendkeys(buf, "$")
|
||||||
|
call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_4', {})
|
||||||
|
|
||||||
|
" clean up
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Loading…
Reference in New Issue
Block a user