summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-08-13 16:41:19 +0100
committerBram Moolenaar <Bram@vim.org>2022-08-13 16:41:19 +0100
commitf0ccfa474a5c4940d03bfc6084e896dc8ac2d791 (patch)
tree2dff4269a2a70e50568d66e3631c47975beb4053
parentcfeb8a584be11758cf71ae02f6c937b06d6bb66f (diff)
patch 9.0.0199: cursor position wrong with two right-aligned virtual textsv9.0.0199
Problem: Cursor position wrong with two right-aligned virtual texts. Solution: Add the padding for right-alignment. (issue #10906)
-rw-r--r--src/charset.c14
-rw-r--r--src/testdir/dumps/Test_prop_right_align_twice_1.dump8
-rw-r--r--src/testdir/dumps/Test_prop_right_align_twice_2.dump8
-rw-r--r--src/testdir/test_textprop.vim23
-rw-r--r--src/version.c2
5 files changed, 53 insertions, 2 deletions
diff --git a/src/charset.c b/src/charset.c
index 2975cdb194..a795984068 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -1181,6 +1181,7 @@ win_lbr_chartabsize(
if (tp->tp_col == MAXCOL)
{
int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
+ int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
int wrap = (tp->tp_flags & TP_FLAG_WRAP);
int len = (int)STRLEN(p);
int n_used = len;
@@ -1193,10 +1194,19 @@ win_lbr_chartabsize(
cells = textprop_size_after_trunc(wp,
below, added, p, &n_used);
}
- // right-aligned does not really matter here, same as
- // "after"
if (below)
cells += wp->w_width - (vcol + size) % wp->w_width;
+ else if (right)
+ {
+ len = wp->w_width - vcol % wp->w_width;
+ if (len > cells + size)
+ // add the padding for right-alignment
+ cells = len - size;
+ else if (len == 0)
+ // padding to right-align in the next line
+ cells += cells > wp->w_width ? 0
+ :wp->w_width - cells;
+ }
#ifdef FEAT_LINEBREAK
no_sbr = TRUE; // don't use 'showbreak' now
#endif
diff --git a/src/testdir/dumps/Test_prop_right_align_twice_1.dump b/src/testdir/dumps/Test_prop_right_align_twice_1.dump
new file mode 100644
index 0000000000..f3f1afca74
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_right_align_twice_1.dump
@@ -0,0 +1,8 @@
+|s+0&#ffffff0|o|m|e| |t|e|x|t| |s|o|m|e| |t|e|x|t| |s|o|m|e| |t|e|x|t| |s|o|m|e| |t|e|x|t| +0&#ffd7ff255|n|o|t|h|i|n|g| |h|e|r|e| +0&#ffffff0@12|S+0#ffffff16#e000002|o|m|e| |e|r@1|o|r
+| +0#0000000#ffffff0@61|A+0#ffffff16#e000002|n|o|t|h|e|r| |e|r@1|o|r
+|l+0#0000000#ffffff0|i|n|e| |t|w>o| @66
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|2|,|8| @10|A|l@1|
diff --git a/src/testdir/dumps/Test_prop_right_align_twice_2.dump b/src/testdir/dumps/Test_prop_right_align_twice_2.dump
new file mode 100644
index 0000000000..dd41c86cf5
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_right_align_twice_2.dump
@@ -0,0 +1,8 @@
+|s+0&#ffffff0|o|m|e| |m|o|r|e| |t|e|x|t|s|o|m|e| |t|e|x|t| |s|o|m|e| |t|e|x|t| |s|o|m|e| |t|e|x|t| |s|o|m|e| |t|e|x|t| +0&#ffd7ff255|n|o|t|h|i|n|g| |h|e|r|e|S+0#ffffff16#e000002|o|m|e| |e|r@1|o
+|r| +0#0000000#ffffff0@60|A+0#ffffff16#e000002|n|o|t|h|e|r| |e|r@1|o|r
+|l+0#0000000#ffffff0|i|n|e| |t|w>o| @66
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|2|,|8| @10|A|l@1|
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index f5ac9c1758..b012f69082 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -2538,6 +2538,29 @@ func Test_prop_inserts_text_highlight()
call delete('XscriptPropsWithHighlight')
endfunc
+func Test_props_with_text_right_align_twice()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ call setline(1, ["some text some text some text some text", 'line two'])
+ call prop_type_add( 'MyErrorText', #{ highlight: 'ErrorMsg' } )
+ call prop_type_add( 'MyPadding', #{ highlight: 'DiffChange' } )
+ call prop_add( 1, 0, #{ type: 'MyPadding', text: ' nothing here', text_wrap: 'wrap'} )
+ call prop_add( 1, 0, #{ type: 'MyErrorText', text: 'Some error', text_wrap: 'wrap', text_align: 'right' } )
+ call prop_add( 1, 0, #{ type: 'MyErrorText', text: 'Another error', text_wrap: 'wrap', text_align: 'right' } )
+ normal G$
+ END
+ call writefile(lines, 'XscriptPropsRightAlign')
+ let buf = RunVimInTerminal('-S XscriptPropsRightAlign', #{rows: 8})
+ call VerifyScreenDump(buf, 'Test_prop_right_align_twice_1', {})
+
+ call term_sendkeys(buf, "ggisome more text\<Esc>G$")
+ call VerifyScreenDump(buf, 'Test_prop_right_align_twice_2', {})
+
+ call StopVimInTerminal(buf)
+ call delete('XscriptPropsRightAlign')
+endfunc
+
func Test_props_with_text_after()
CheckRunVimInTerminal
diff --git a/src/version.c b/src/version.c
index 3f4c7edb87..2d1b5ccfef 100644
--- a/src/version.c
+++ b/src/version.c
@@ -736,6 +736,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 199,
+/**/
198,
/**/
197,