mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.0.0178: cursor position wrong with virtual text before Tab
Problem: Cursor position wrong with virtual text before Tab. Solution: Use the byte length, not the cell with, to compare the column. Correct tab size after text prop. (closes #10866)
This commit is contained in:
parent
8f49e690dc
commit
e428fa04a7
@ -1130,7 +1130,8 @@ win_lbr_chartabsize(
|
|||||||
# ifdef FEAT_PROP_POPUP
|
# ifdef FEAT_PROP_POPUP
|
||||||
if (cts->cts_has_prop_with_text && *line != NUL)
|
if (cts->cts_has_prop_with_text && *line != NUL)
|
||||||
{
|
{
|
||||||
int normal_size = size;
|
int tab_size = size;
|
||||||
|
int charlen = mb_ptr2len(s);
|
||||||
int i;
|
int i;
|
||||||
int col = (int)(s - line);
|
int col = (int)(s - line);
|
||||||
garray_T *gap = &wp->w_buffer->b_textprop_text;
|
garray_T *gap = &wp->w_buffer->b_textprop_text;
|
||||||
@ -1143,7 +1144,7 @@ win_lbr_chartabsize(
|
|||||||
// copy, the text prop may actually have been removed from the line.
|
// copy, the text prop may actually have been removed from the line.
|
||||||
if (tp->tp_id < 0
|
if (tp->tp_id < 0
|
||||||
&& ((tp->tp_col - 1 >= col
|
&& ((tp->tp_col - 1 >= col
|
||||||
&& tp->tp_col - 1 < col + normal_size)
|
&& tp->tp_col - 1 < col + charlen)
|
||||||
|| (tp->tp_col == MAXCOL && (s[0] == NUL || s[1] == NUL)
|
|| (tp->tp_col == MAXCOL && (s[0] == NUL || s[1] == NUL)
|
||||||
&& cts->cts_with_trailing))
|
&& cts->cts_with_trailing))
|
||||||
&& -tp->tp_id - 1 < gap->ga_len)
|
&& -tp->tp_id - 1 < gap->ga_len)
|
||||||
@ -1179,6 +1180,13 @@ win_lbr_chartabsize(
|
|||||||
}
|
}
|
||||||
cts->cts_cur_text_width += cells;
|
cts->cts_cur_text_width += cells;
|
||||||
size += cells;
|
size += cells;
|
||||||
|
if (*s == TAB)
|
||||||
|
{
|
||||||
|
// tab size changes because of the inserted text
|
||||||
|
size -= tab_size;
|
||||||
|
tab_size = win_chartabsize(wp, s, vcol + size);
|
||||||
|
size += tab_size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tp->tp_col != MAXCOL && tp->tp_col - 1 > col)
|
if (tp->tp_col != MAXCOL && tp->tp_col - 1 > col)
|
||||||
@ -1525,11 +1533,6 @@ getvcol(
|
|||||||
*end = vcol + incr - 1;
|
*end = vcol + incr - 1;
|
||||||
if (cursor != NULL)
|
if (cursor != NULL)
|
||||||
{
|
{
|
||||||
#ifdef FEAT_PROP_POPUP
|
|
||||||
if ((State & MODE_INSERT) == 0)
|
|
||||||
// cursor is after inserted text
|
|
||||||
vcol += cts.cts_cur_text_width;
|
|
||||||
#endif
|
|
||||||
if (*ptr == TAB
|
if (*ptr == TAB
|
||||||
&& (State & MODE_NORMAL)
|
&& (State & MODE_NORMAL)
|
||||||
&& !wp->w_p_list
|
&& !wp->w_p_list
|
||||||
@ -1539,9 +1542,16 @@ getvcol(
|
|||||||
)
|
)
|
||||||
*cursor = vcol + incr - 1; // cursor at end
|
*cursor = vcol + incr - 1; // cursor at end
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
#ifdef FEAT_PROP_POPUP
|
||||||
|
if ((State & MODE_INSERT) == 0)
|
||||||
|
// cursor is after inserted text
|
||||||
|
vcol += cts.cts_cur_text_width;
|
||||||
|
#endif
|
||||||
*cursor = vcol + head; // cursor at start
|
*cursor = vcol + head; // cursor at start
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get virtual cursor column in the current window, pretending 'list' is off.
|
* Get virtual cursor column in the current window, pretending 'list' is off.
|
||||||
|
8
src/testdir/dumps/Test_prop_before_tab_01.dump
Normal file
8
src/testdir/dumps/Test_prop_before_tab_01.dump
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|1+0&#ffff4012|2|3| +0&#ffffff0@3> |x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7| +0&#ffffff0|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8| +0&#ffffff0@7|x| @57
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8|9| +0&#ffffff0@6|x| @57
|
||||||
|
@8|A+0&#ffff4012|B|C|x+0&#ffffff0| @62
|
||||||
|
@8|x|A+0&#ffff4012|B|C| +0&#ffffff0@62
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
| +0#0000000&@56|1|,|1|-|8| @8|A|l@1|
|
8
src/testdir/dumps/Test_prop_before_tab_02.dump
Normal file
8
src/testdir/dumps/Test_prop_before_tab_02.dump
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|1+0&#ffff4012|2|3| +0&#ffffff0@4>x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7| +0&#ffffff0|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8| +0&#ffffff0@7|x| @57
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8|9| +0&#ffffff0@6|x| @57
|
||||||
|
@8|A+0&#ffff4012|B|C|x+0&#ffffff0| @62
|
||||||
|
@8|x|A+0&#ffff4012|B|C| +0&#ffffff0@62
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
| +0#0000000&@56|1|,|2|-|9| @8|A|l@1|
|
8
src/testdir/dumps/Test_prop_before_tab_03.dump
Normal file
8
src/testdir/dumps/Test_prop_before_tab_03.dump
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|1+0&#ffff4012|2|3| +0&#ffffff0@4|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7> +0&#ffffff0|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8| +0&#ffffff0@7|x| @57
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8|9| +0&#ffffff0@6|x| @57
|
||||||
|
@8|A+0&#ffff4012|B|C|x+0&#ffffff0| @62
|
||||||
|
@8|x|A+0&#ffff4012|B|C| +0&#ffffff0@62
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
| +0#0000000&@56|2|,|1|-|8| @8|A|l@1|
|
8
src/testdir/dumps/Test_prop_before_tab_04.dump
Normal file
8
src/testdir/dumps/Test_prop_before_tab_04.dump
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|1+0&#ffff4012|2|3| +0&#ffffff0@4|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7| +0&#ffffff0>x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8| +0&#ffffff0@7|x| @57
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8|9| +0&#ffffff0@6|x| @57
|
||||||
|
@8|A+0&#ffff4012|B|C|x+0&#ffffff0| @62
|
||||||
|
@8|x|A+0&#ffff4012|B|C| +0&#ffffff0@62
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
| +0#0000000&@56|2|,|2|-|9| @8|A|l@1|
|
8
src/testdir/dumps/Test_prop_before_tab_05.dump
Normal file
8
src/testdir/dumps/Test_prop_before_tab_05.dump
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|1+0&#ffff4012|2|3| +0&#ffffff0@4|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7| +0&#ffffff0|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8| +0&#ffffff0@6> |x| @57
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8|9| +0&#ffffff0@6|x| @57
|
||||||
|
@8|A+0&#ffff4012|B|C|x+0&#ffffff0| @62
|
||||||
|
@8|x|A+0&#ffff4012|B|C| +0&#ffffff0@62
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
| +0#0000000&@56|3|,|1|-|1|6| @7|A|l@1|
|
8
src/testdir/dumps/Test_prop_before_tab_06.dump
Normal file
8
src/testdir/dumps/Test_prop_before_tab_06.dump
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|1+0&#ffff4012|2|3| +0&#ffffff0@4|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7| +0&#ffffff0|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8| +0&#ffffff0@7>x| @57
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8|9| +0&#ffffff0@6|x| @57
|
||||||
|
@8|A+0&#ffff4012|B|C|x+0&#ffffff0| @62
|
||||||
|
@8|x|A+0&#ffff4012|B|C| +0&#ffffff0@62
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
| +0#0000000&@56|3|,|2|-|1|7| @7|A|l@1|
|
8
src/testdir/dumps/Test_prop_before_tab_07.dump
Normal file
8
src/testdir/dumps/Test_prop_before_tab_07.dump
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|1+0&#ffff4012|2|3| +0&#ffffff0@4|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7| +0&#ffffff0|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8| +0&#ffffff0@7|x| @57
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8|9| +0&#ffffff0@5> |x| @57
|
||||||
|
@8|A+0&#ffff4012|B|C|x+0&#ffffff0| @62
|
||||||
|
@8|x|A+0&#ffff4012|B|C| +0&#ffffff0@62
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
| +0#0000000&@56|4|,|1|-|1|6| @7|A|l@1|
|
8
src/testdir/dumps/Test_prop_before_tab_08.dump
Normal file
8
src/testdir/dumps/Test_prop_before_tab_08.dump
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|1+0&#ffff4012|2|3| +0&#ffffff0@4|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7| +0&#ffffff0|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8| +0&#ffffff0@7|x| @57
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8|9| +0&#ffffff0@6>x| @57
|
||||||
|
@8|A+0&#ffff4012|B|C|x+0&#ffffff0| @62
|
||||||
|
@8|x|A+0&#ffff4012|B|C| +0&#ffffff0@62
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
| +0#0000000&@56|4|,|2|-|1|7| @7|A|l@1|
|
8
src/testdir/dumps/Test_prop_before_tab_09.dump
Normal file
8
src/testdir/dumps/Test_prop_before_tab_09.dump
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|1+0&#ffff4012|2|3| +0&#ffffff0@4|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7| +0&#ffffff0|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8| +0&#ffffff0@7|x| @57
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8|9| +0&#ffffff0@6|x| @57
|
||||||
|
@8|A+0&#ffff4012|B|C>x+0&#ffffff0| @62
|
||||||
|
@8|x|A+0&#ffff4012|B|C| +0&#ffffff0@62
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
| +0#0000000&@56|5|,|2|-|1|2| @7|A|l@1|
|
8
src/testdir/dumps/Test_prop_before_tab_10.dump
Normal file
8
src/testdir/dumps/Test_prop_before_tab_10.dump
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|1+0&#ffff4012|2|3| +0&#ffffff0@4|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7| +0&#ffffff0|x| @65
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8| +0&#ffffff0@7|x| @57
|
||||||
|
|1+0&#ffff4012|2|3|4|5|6|7|8|9| +0&#ffffff0@6|x| @57
|
||||||
|
@8|A+0&#ffff4012|B|C|x+0&#ffffff0| @62
|
||||||
|
@8>x|A+0&#ffff4012|B|C| +0&#ffffff0@62
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
| +0#0000000&@56|6|,|2|-|9| @8|A|l@1|
|
@ -974,10 +974,12 @@ func Test_prop_line2byte()
|
|||||||
call assert_equal(1489, line2byte(400))
|
call assert_equal(1489, line2byte(400))
|
||||||
bwipe!
|
bwipe!
|
||||||
|
|
||||||
|
call ch_logfile('logfile', 'w')
|
||||||
" Add many lines so that the data block is split.
|
" Add many lines so that the data block is split.
|
||||||
" With and without props should give the same result.
|
" With and without props should give the same result.
|
||||||
call Run_test_with_line2byte(0)
|
call Run_test_with_line2byte(0)
|
||||||
call Run_test_with_line2byte(1)
|
call Run_test_with_line2byte(1)
|
||||||
|
call ch_logfile('', 'w')
|
||||||
|
|
||||||
call prop_type_delete('comment')
|
call prop_type_delete('comment')
|
||||||
endfunc
|
endfunc
|
||||||
@ -1893,6 +1895,46 @@ func Test_prop_after_tab()
|
|||||||
call delete('XscriptPropAfterTab')
|
call delete('XscriptPropAfterTab')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_prop_before_tab()
|
||||||
|
CheckRunVimInTerminal
|
||||||
|
|
||||||
|
let lines =<< trim END
|
||||||
|
call setline(1, ["\tx"]->repeat(6))
|
||||||
|
call prop_type_add('test', #{highlight: 'Search'})
|
||||||
|
call prop_add(1, 1, #{type: 'test', text: '123'})
|
||||||
|
call prop_add(2, 1, #{type: 'test', text: '1234567'})
|
||||||
|
call prop_add(3, 1, #{type: 'test', text: '12345678'})
|
||||||
|
call prop_add(4, 1, #{type: 'test', text: '123456789'})
|
||||||
|
call prop_add(5, 2, #{type: 'test', text: 'ABC'})
|
||||||
|
call prop_add(6, 3, #{type: 'test', text: 'ABC'})
|
||||||
|
normal gg0
|
||||||
|
END
|
||||||
|
call writefile(lines, 'XscriptPropBeforeTab')
|
||||||
|
let buf = RunVimInTerminal('-S XscriptPropBeforeTab', #{rows: 8})
|
||||||
|
call VerifyScreenDump(buf, 'Test_prop_before_tab_01', {})
|
||||||
|
call term_sendkeys(buf, "$")
|
||||||
|
call VerifyScreenDump(buf, 'Test_prop_before_tab_02', {})
|
||||||
|
call term_sendkeys(buf, "j0")
|
||||||
|
call VerifyScreenDump(buf, 'Test_prop_before_tab_03', {})
|
||||||
|
call term_sendkeys(buf, "$")
|
||||||
|
call VerifyScreenDump(buf, 'Test_prop_before_tab_04', {})
|
||||||
|
call term_sendkeys(buf, "j0")
|
||||||
|
call VerifyScreenDump(buf, 'Test_prop_before_tab_05', {})
|
||||||
|
call term_sendkeys(buf, "$")
|
||||||
|
call VerifyScreenDump(buf, 'Test_prop_before_tab_06', {})
|
||||||
|
call term_sendkeys(buf, "j0")
|
||||||
|
call VerifyScreenDump(buf, 'Test_prop_before_tab_07', {})
|
||||||
|
call term_sendkeys(buf, "$")
|
||||||
|
call VerifyScreenDump(buf, 'Test_prop_before_tab_08', {})
|
||||||
|
call term_sendkeys(buf, "j")
|
||||||
|
call VerifyScreenDump(buf, 'Test_prop_before_tab_09', {})
|
||||||
|
call term_sendkeys(buf, "j")
|
||||||
|
call VerifyScreenDump(buf, 'Test_prop_before_tab_10', {})
|
||||||
|
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
call delete('XscriptPropBeforeTab')
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_prop_after_linebreak()
|
func Test_prop_after_linebreak()
|
||||||
CheckRunVimInTerminal
|
CheckRunVimInTerminal
|
||||||
|
|
||||||
|
@ -735,6 +735,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
178,
|
||||||
/**/
|
/**/
|
||||||
177,
|
177,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user