From 28c9f895716cfa8f1220bc41b72a534c0e10cabe Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 14 Aug 2022 13:28:55 +0100 Subject: [PATCH] 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 #10914) --- src/charset.c | 5 ++- src/structs.h | 3 ++ .../dumps/Test_prop_insert_start_incl_1.dump | 8 +++++ .../dumps/Test_prop_insert_start_incl_2.dump | 8 +++++ .../dumps/Test_prop_insert_start_incl_3.dump | 8 +++++ .../dumps/Test_prop_insert_start_incl_4.dump | 8 +++++ .../dumps/Test_prop_insert_start_incl_5.dump | 8 +++++ src/testdir/test_textprop.vim | 31 +++++++++++++++++++ src/textprop.c | 4 ++- src/version.c | 2 ++ 10 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 src/testdir/dumps/Test_prop_insert_start_incl_1.dump create mode 100644 src/testdir/dumps/Test_prop_insert_start_incl_2.dump create mode 100644 src/testdir/dumps/Test_prop_insert_start_incl_3.dump create mode 100644 src/testdir/dumps/Test_prop_insert_start_incl_4.dump create mode 100644 src/testdir/dumps/Test_prop_insert_start_incl_5.dump diff --git a/src/charset.c b/src/charset.c index a795984068d55..160495222a801 100644 --- a/src/charset.c +++ b/src/charset.c @@ -1212,6 +1212,7 @@ win_lbr_chartabsize( #endif } cts->cts_cur_text_width += cells; + cts->cts_start_incl = tp->tp_flags & TP_FLAG_START_INCL; size += cells; if (*s == TAB) { @@ -1585,7 +1586,9 @@ getvcol( else { #ifdef FEAT_PROP_POPUP - if ((State & MODE_INSERT) == 0 && !on_NUL) + // in Insert mode, if "start_incl" is true the text gets inserted + // after the virtual text, thus add its width + if (((State & MODE_INSERT) == 0 || cts.cts_start_incl) && !on_NUL) // cursor is after inserted text, unless on the NUL vcol += cts.cts_cur_text_width; #endif diff --git a/src/structs.h b/src/structs.h index fcc9c79c3ad09..fb56e012aee96 100644 --- a/src/structs.h +++ b/src/structs.h @@ -815,6 +815,8 @@ typedef struct textprop_S #define TP_FLAG_WRAP 0x40 // virtual text wraps - when missing // text is truncated +#define TP_FLAG_START_INCL 0x80 // "start_incl" copied from proptype + #define PROP_TEXT_MIN_CELLS 4 // minimun number of cells to use for // the text, even when truncating @@ -4587,6 +4589,7 @@ typedef struct { int cts_cur_text_width; // width of current inserted text int cts_with_trailing; // include size of trailing props with // last character + int cts_start_incl; // prop has true "start_incl" arg #endif int cts_vcol; // virtual column at current position } chartabsize_T; diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_1.dump b/src/testdir/dumps/Test_prop_insert_start_incl_1.dump new file mode 100644 index 0000000000000..deb67d50be94e --- /dev/null +++ b/src/testdir/dumps/Test_prop_insert_start_incl_1.dump @@ -0,0 +1,8 @@ +|t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| >o+0#0000000&|n|e| |t|e|x|t| |b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @29 +|~+0#4040ff13&| @58 +|~| @58 +|~| @58 +|~| @58 +|~| @58 +|~| @58 +| +0#0000000&@41|1|,|6|-|1|2| @7|A|l@1| diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_2.dump b/src/testdir/dumps/Test_prop_insert_start_incl_2.dump new file mode 100644 index 0000000000000..73cf64881d16f --- /dev/null +++ b/src/testdir/dumps/Test_prop_insert_start_incl_2.dump @@ -0,0 +1,8 @@ +|t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| >o+0#0000000&|n|e| |t|e|x|t| |b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @29 +|~+0#4040ff13&| @58 +|~| @58 +|~| @58 +|~| @58 +|~| @58 +|~| @58 +|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@29|1|,|6|-|1|2| @7|A|l@1| diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_3.dump b/src/testdir/dumps/Test_prop_insert_start_incl_3.dump new file mode 100644 index 0000000000000..cc4de01c75840 --- /dev/null +++ b/src/testdir/dumps/Test_prop_insert_start_incl_3.dump @@ -0,0 +1,8 @@ +|t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| |x+0#0000000&>x|o|n|e| |t|e|x|t| |b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @27 +|~+0#4040ff13&| @58 +|~| @58 +|~| @58 +|~| @58 +|~| @58 +|~| @58 +| +0#0000000&@41|1|,|7|-|1|3| @7|A|l@1| diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_4.dump b/src/testdir/dumps/Test_prop_insert_start_incl_4.dump new file mode 100644 index 0000000000000..75e2580238395 --- /dev/null +++ b/src/testdir/dumps/Test_prop_insert_start_incl_4.dump @@ -0,0 +1,8 @@ +|t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| |x+0#0000000&@1|o|n|e| |t|e|x|t| >b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @27 +|~+0#4040ff13&| @58 +|~| @58 +|~| @58 +|~| @58 +|~| @58 +|~| @58 +|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@29|1|,|1|7|-|2|3| @6|A|l@1| diff --git a/src/testdir/dumps/Test_prop_insert_start_incl_5.dump b/src/testdir/dumps/Test_prop_insert_start_incl_5.dump new file mode 100644 index 0000000000000..5cbee12e318ea --- /dev/null +++ b/src/testdir/dumps/Test_prop_insert_start_incl_5.dump @@ -0,0 +1,8 @@ +|t+0&#ffffff0|e|x|t| |a+0#4040ff13&|f|t|e|r| |x+0#0000000&@1|o|n|e| |t|e|x|t| |y>y|b+0#4040ff13&|e|f|o|r|e| |t+0#0000000&|w|o| @25 +|~+0#4040ff13&| @58 +|~| @58 +|~| @58 +|~| @58 +|~| @58 +|~| @58 +| +0#0000000&@41|1|,|1|8|-|2|4| @6|A|l@1| diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim index b702340a3edf2..2e72db9b9baaf 100644 --- a/src/testdir/test_textprop.vim +++ b/src/testdir/test_textprop.vim @@ -2914,4 +2914,35 @@ def Test_insert_text_before_virtual_text() bwipe! enddef +func Test_insert_text_start_incl() + CheckRunVimInTerminal + + let lines =<< trim END + vim9script + setline(1, 'text one text two') + + prop_type_add('propincl', {highlight: 'NonText', start_incl: true}) + prop_add(1, 6, {type: 'propincl', text: 'after '}) + cursor(1, 6) + prop_type_add('propnotincl', {highlight: 'NonText', start_incl: false}) + prop_add(1, 15, {type: 'propnotincl', text: 'before '}) + END + call writefile(lines, 'XscriptPropsStartIncl') + let buf = RunVimInTerminal('-S XscriptPropsStartIncl', #{rows: 8, cols: 60}) + call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_1', {}) + + call term_sendkeys(buf, "i") + call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_2', {}) + call term_sendkeys(buf, "xx\") + call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_3', {}) + + call term_sendkeys(buf, "2wi") + call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_4', {}) + call term_sendkeys(buf, "yy\") + call VerifyScreenDump(buf, 'Test_prop_insert_start_incl_5', {}) + + call StopVimInTerminal(buf) + call delete('XscriptPropsStartIncl') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/textprop.c b/src/textprop.c index 88156c272e1ce..e2de73165beaa 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -294,7 +294,9 @@ prop_add_one( tmp_prop.tp_type = type->pt_id; tmp_prop.tp_flags = text_flags | (lnum > start_lnum ? TP_FLAG_CONT_PREV : 0) - | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0); + | (lnum < end_lnum ? TP_FLAG_CONT_NEXT : 0) + | ((type->pt_flags & PT_FLAG_INS_START_INCL) + ? TP_FLAG_START_INCL : 0); mch_memmove(newprops + i * sizeof(textprop_T), &tmp_prop, sizeof(textprop_T)); diff --git a/src/version.c b/src/version.c index 3b5193fa58a37..7769ccb14caca 100644 --- a/src/version.c +++ b/src/version.c @@ -735,6 +735,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 205, /**/ 204, /**/