mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.0205: cursor in wrong position when inserting after virtual text
Problem: Cursor in wrong position when inserting after virtual text. (Ben
Jackson)
Solution: Put the cursor after the virtual text, where the text will be
inserted. (closes vim/vim#10914)
28c9f89571
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -1092,7 +1092,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en
|
||||
// cursor at end
|
||||
*cursor = vcol + incr - 1;
|
||||
} else {
|
||||
if ((State & MODE_INSERT) == 0 && !on_NUL) {
|
||||
if (((State & MODE_INSERT) == 0 || !cts.cts_has_right_gravity) && !on_NUL) {
|
||||
// cursor is after inserted text, unless on the NUL
|
||||
vcol += cts.cts_cur_text_width;
|
||||
}
|
||||
|
||||
@@ -325,6 +325,7 @@ void init_chartabsize_arg(chartabsize_T *cts, win_T *wp, linenr_T lnum, colnr_T
|
||||
cts->cts_ptr = ptr;
|
||||
cts->cts_cur_text_width = 0;
|
||||
cts->cts_has_virt_text = false;
|
||||
cts->cts_has_right_gravity = true;
|
||||
cts->cts_row = lnum - 1;
|
||||
|
||||
if (cts->cts_row >= 0) {
|
||||
@@ -425,6 +426,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp)
|
||||
Decoration decor = get_decor(mark);
|
||||
if (decor.virt_text_pos == kVTInline) {
|
||||
cts->cts_cur_text_width += decor.virt_text_width;
|
||||
cts->cts_has_right_gravity = mt_right(mark);
|
||||
size += decor.virt_text_width;
|
||||
if (*s == TAB) {
|
||||
// tab size changes because of the inserted text
|
||||
|
||||
@@ -14,6 +14,7 @@ typedef struct {
|
||||
int cts_row;
|
||||
|
||||
bool cts_has_virt_text; // true if if a property inserts text
|
||||
bool cts_has_right_gravity;
|
||||
int cts_cur_text_width; // width of current inserted text
|
||||
MarkTreeIter cts_iter[1];
|
||||
// TODO(bfredl): iterator in to the marktree for scanning virt text
|
||||
|
||||
@@ -1652,11 +1652,12 @@ bbbbbbb]])
|
||||
]]}
|
||||
end)
|
||||
|
||||
feed('8l')
|
||||
it('visual select highlight is correct with virtual text attatched to', function()
|
||||
insert('foo foo foo foo')
|
||||
feed('0')
|
||||
meths.buf_set_extmark(0, ns, 0, 8,
|
||||
{ virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
|
||||
{ virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline' })
|
||||
feed('8l')
|
||||
screen:expect { grid = [[
|
||||
foo foo {28:virtual text}^foo foo |
|
||||
@@ -1696,6 +1697,50 @@ bbbbbbb]])
|
||||
{24:-- VISUAL --} |
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('cursor position is correct when inserting around a virtual text with right gravity set to false', function()
|
||||
insert('foo foo foo foo')
|
||||
meths.buf_set_extmark(0, ns, 0, 8,
|
||||
{ virt_text = { { 'virtual text', 'Special' } }, virt_text_pos = 'inline', right_gravity = false })
|
||||
feed('0')
|
||||
feed('8l')
|
||||
screen:expect { grid = [[
|
||||
foo foo {28:virtual text}^foo foo |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
|
|
||||
]]}
|
||||
|
||||
feed('i')
|
||||
screen:expect { grid = [[
|
||||
foo foo {28:virtual text}^foo foo |
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{1:~ }|
|
||||
{24:-- INSERT --} |
|
||||
]]}
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('decorations: virtual lines', function()
|
||||
|
||||
Reference in New Issue
Block a user