mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.3095: with 'virtualedit' set to "block" block selection is wrong
Problem: With 'virtualedit' set to "block" block selection is wrong after
using "$". (Marco Trosi)
Solution: Compute the longest selected line. (closes vim/vim#8495)
b17ab86e7b
This commit is contained in:
parent
3d0149f984
commit
f2d84df4a8
@ -1222,12 +1222,33 @@ static void win_update(win_T *wp, Providers *providers)
|
|||||||
}
|
}
|
||||||
|
|
||||||
getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc);
|
getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc);
|
||||||
curwin->w_ve_flags = save_ve_flags;
|
|
||||||
toc++;
|
toc++;
|
||||||
|
curwin->w_ve_flags = save_ve_flags;
|
||||||
// Highlight to the end of the line, unless 'virtualedit' has
|
// Highlight to the end of the line, unless 'virtualedit' has
|
||||||
// "block".
|
// "block".
|
||||||
if (curwin->w_curswant == MAXCOL && !(get_ve_flags() & VE_BLOCK)) {
|
if (curwin->w_curswant == MAXCOL) {
|
||||||
toc = MAXCOL;
|
if (get_ve_flags() & VE_BLOCK) {
|
||||||
|
pos_T pos;
|
||||||
|
int cursor_above = curwin->w_cursor.lnum < VIsual.lnum;
|
||||||
|
|
||||||
|
// Need to find the longest line.
|
||||||
|
toc = 0;
|
||||||
|
pos.coladd = 0;
|
||||||
|
for (pos.lnum = curwin->w_cursor.lnum;
|
||||||
|
cursor_above ? pos.lnum <= VIsual.lnum : pos.lnum >= VIsual.lnum;
|
||||||
|
pos.lnum += cursor_above ? 1 : -1) {
|
||||||
|
colnr_T t;
|
||||||
|
|
||||||
|
pos.col = STRLEN(ml_get_buf(wp->w_buffer, pos.lnum, false));
|
||||||
|
getvvcol(wp, &pos, NULL, NULL, &t);
|
||||||
|
if (toc < t) {
|
||||||
|
toc = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toc++;
|
||||||
|
} else {
|
||||||
|
toc = MAXCOL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromc != wp->w_old_cursor_fcol
|
if (fromc != wp->w_old_cursor_fcol
|
||||||
|
@ -1124,6 +1124,9 @@ func Test_visual_block_with_virtualedit()
|
|||||||
call term_sendkeys(buf, "\<C-V>gg$")
|
call term_sendkeys(buf, "\<C-V>gg$")
|
||||||
call VerifyScreenDump(buf, 'Test_visual_block_with_virtualedit', {})
|
call VerifyScreenDump(buf, 'Test_visual_block_with_virtualedit', {})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, "\<Esc>gg\<C-V>G$")
|
||||||
|
call VerifyScreenDump(buf, 'Test_visual_block_with_virtualedit2', {})
|
||||||
|
|
||||||
" clean up
|
" clean up
|
||||||
call term_sendkeys(buf, "\<Esc>")
|
call term_sendkeys(buf, "\<Esc>")
|
||||||
call StopVimInTerminal(buf)
|
call StopVimInTerminal(buf)
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
-- Test visual line mode selection redraw after scrolling
|
|
||||||
|
|
||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
|
||||||
local Screen = require('test.functional.ui.screen')
|
local Screen = require('test.functional.ui.screen')
|
||||||
@ -10,6 +8,7 @@ local feed_command = helpers.feed_command
|
|||||||
local funcs = helpers.funcs
|
local funcs = helpers.funcs
|
||||||
local meths = helpers.meths
|
local meths = helpers.meths
|
||||||
local eq = helpers.eq
|
local eq = helpers.eq
|
||||||
|
local exec = helpers.exec
|
||||||
|
|
||||||
describe('visual line mode', function()
|
describe('visual line mode', function()
|
||||||
local screen
|
local screen
|
||||||
@ -40,3 +39,44 @@ describe('visual line mode', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('visual block mode', function()
|
||||||
|
it('shows selection correctly with virtualedit=block', function()
|
||||||
|
clear()
|
||||||
|
local screen = Screen.new(30, 7)
|
||||||
|
screen:set_default_attr_ids({
|
||||||
|
[1] = {bold = true}, -- ModeMsg
|
||||||
|
[2] = {background = Screen.colors.LightGrey}, -- Visual
|
||||||
|
[3] = {foreground = Screen.colors.Blue, bold = true} -- NonText
|
||||||
|
})
|
||||||
|
screen:attach()
|
||||||
|
|
||||||
|
exec([[
|
||||||
|
call setline(1, ['aaaaaa', 'bbbb', 'cc'])
|
||||||
|
set virtualedit=block
|
||||||
|
normal G
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('<C-V>gg$')
|
||||||
|
screen:expect([[
|
||||||
|
{2:aaaaaa}^ |
|
||||||
|
{2:bbbb } |
|
||||||
|
{2:cc } |
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{1:-- VISUAL BLOCK --} |
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('<Esc>gg<C-V>G$')
|
||||||
|
screen:expect([[
|
||||||
|
{2:aaaaaa } |
|
||||||
|
{2:bbbb } |
|
||||||
|
{2:cc}^ {2: } |
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{3:~ }|
|
||||||
|
{1:-- VISUAL BLOCK --} |
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user