To: vim_dev@googlegroups.com Subject: Patch 9.0.0199 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0199 Problem: Cursor position wrong with two right-aligned virtual texts. Solution: Add the padding for right-alignment. (issue #10906) Files: src/charset.c, src/testdir/test_textprop.vim, src/testdir/dumps/Test_prop_right_align_twice_1.dump, src/testdir/dumps/Test_prop_right_align_twice_2.dump *** ../vim-9.0.0198/src/charset.c 2022-08-09 18:24:58.594059458 +0100 --- src/charset.c 2022-08-13 16:25:56.450008425 +0100 *************** *** 1181,1186 **** --- 1181,1187 ---- 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,1202 **** 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; #ifdef FEAT_LINEBREAK no_sbr = TRUE; // don't use 'showbreak' now #endif --- 1194,1212 ---- cells = textprop_size_after_trunc(wp, below, added, p, &n_used); } 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 *** ../vim-9.0.0198/src/testdir/test_textprop.vim 2022-08-12 13:05:27.567326156 +0100 --- src/testdir/test_textprop.vim 2022-08-13 16:27:18.897764856 +0100 *************** *** 2538,2543 **** --- 2538,2566 ---- 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\G$") + call VerifyScreenDump(buf, 'Test_prop_right_align_twice_2', {}) + + call StopVimInTerminal(buf) + call delete('XscriptPropsRightAlign') + endfunc + func Test_props_with_text_after() CheckRunVimInTerminal *** ../vim-9.0.0198/src/testdir/dumps/Test_prop_right_align_twice_1.dump 2022-08-13 16:29:51.481316569 +0100 --- src/testdir/dumps/Test_prop_right_align_twice_1.dump 2022-08-13 16:27:24.761747569 +0100 *************** *** 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| *** ../vim-9.0.0198/src/testdir/dumps/Test_prop_right_align_twice_2.dump 2022-08-13 16:29:51.485316557 +0100 --- src/testdir/dumps/Test_prop_right_align_twice_2.dump 2022-08-13 16:27:25.917744164 +0100 *************** *** 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| *** ../vim-9.0.0198/src/version.c 2022-08-13 14:09:40.979749238 +0100 --- src/version.c 2022-08-13 15:53:52.416551964 +0100 *************** *** 737,738 **** --- 737,740 ---- { /* Add new patch number below this line */ + /**/ + 199, /**/ -- Luxury. We used to have to get out of the lake at three o'clock in the morning, clean the lake, eat a handful of hot gravel, go to work at the mill every day for tuppence a month, come home, and Dad would beat us around the head and neck with a broken bottle, if we were LUCKY! /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///