Patch 9.0.0154

4 views
Skip to first unread message

Bram Moolenaar

unread,
Aug 6, 2022, 12:12:16 PM8/6/22
to vim...@googlegroups.com

Patch 9.0.0154
Problem: Text properties wrong after splitting a line.
Solution: Check for text properties after the line. (closes #10857)
Files: src/textprop.c, src/ops.c, src/testdir/test_textprop.vim,
src/testdir/dumps/Test_prop_with_text_after_join_split_1.dump,
src/testdir/dumps/Test_prop_with_text_after_join_split_2.dump,
src/testdir/dumps/Test_prop_with_text_after_join_split_3.dump,
src/testdir/dumps/Test_prop_with_text_after_join_split_4.dump,
src/testdir/dumps/Test_prop_with_text_after_join_split_5.dump


*** ../vim-9.0.0153/src/textprop.c 2022-08-06 13:47:16.212982332 +0100
--- src/textprop.c 2022-08-06 16:56:32.185879951 +0100
***************
*** 621,626 ****
--- 621,628 ----
* Return the number of text properties on line "lnum" in the current buffer.
* When "only_starting" is true only text properties starting in this line will
* be considered.
+ * When "last_line" is FALSE then text properties after the line are not
+ * counted.
*/
int
count_props(linenr_T lnum, int only_starting, int last_line)
***************
*** 634,640 ****
for (i = 0; i < proplen; ++i)
{
mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop));
! // A prop is droppend when in the first line and it continues from the
// previous line, or when not in the last line and it is virtual text
// after the line.
if ((only_starting && (prop.tp_flags & TP_FLAG_CONT_PREV))
--- 636,642 ----
for (i = 0; i < proplen; ++i)
{
mch_memmove(&prop, props + i * sizeof(prop), sizeof(prop));
! // A prop is dropped when in the first line and it continues from the
// previous line, or when not in the last line and it is virtual text
// after the line.
if ((only_starting && (prop.tp_flags & TP_FLAG_CONT_PREV))
***************
*** 706,712 ****
}

/*
! * Add "text_props" with "text_prop_count" text propertis to line "lnum".
*/
void
add_text_props(linenr_T lnum, textprop_T *text_props, int text_prop_count)
--- 708,714 ----
}

/*
! * Add "text_props" with "text_prop_count" text properties to line "lnum".
*/
void
add_text_props(linenr_T lnum, textprop_T *text_props, int text_prop_count)
***************
*** 2031,2038 ****
pt = text_prop_type_by_id(curbuf, prop.tp_type);
start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL));
end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL));
! cont_prev = prop.tp_col + !start_incl <= kept;
! cont_next = skipped <= prop.tp_col + prop.tp_len - !end_incl;

if (cont_prev && ga_grow(&prevprop, 1) == OK)
{
--- 2033,2041 ----
pt = text_prop_type_by_id(curbuf, prop.tp_type);
start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL));
end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL));
! cont_prev = prop.tp_col != MAXCOL && prop.tp_col + !start_incl <= kept;
! cont_next = prop.tp_col != MAXCOL
! && skipped <= prop.tp_col + prop.tp_len - !end_incl;

if (cont_prev && ga_grow(&prevprop, 1) == OK)
{
***************
*** 2048,2064 ****

// Only add the property to the next line if the length is bigger than
// zero.
! if (cont_next && ga_grow(&nextprop, 1) == OK)
{
textprop_T *p = ((textprop_T *)nextprop.ga_data) + nextprop.ga_len;
*p = prop;
++nextprop.ga_len;
! if (p->tp_col > skipped)
! p->tp_col -= skipped - 1;
! else
{
! p->tp_len -= skipped - p->tp_col;
! p->tp_col = 1;
}
if (cont_prev)
p->tp_flags |= TP_FLAG_CONT_PREV;
--- 2051,2072 ----

// Only add the property to the next line if the length is bigger than
// zero.
! if ((cont_next || prop.tp_col == MAXCOL)
! && ga_grow(&nextprop, 1) == OK)
{
textprop_T *p = ((textprop_T *)nextprop.ga_data) + nextprop.ga_len;
+
*p = prop;
++nextprop.ga_len;
! if (p->tp_col != MAXCOL)
{
! if (p->tp_col > skipped)
! p->tp_col -= skipped - 1;
! else
! {
! p->tp_len -= skipped - p->tp_col;
! p->tp_col = 1;
! }
}
if (cont_prev)
p->tp_flags |= TP_FLAG_CONT_PREV;
*** ../vim-9.0.0153/src/ops.c 2022-08-01 22:18:30.483764954 +0100
--- src/ops.c 2022-08-06 16:21:15.911038402 +0100
***************
*** 1944,1950 ****
}

/*
! * Join 'count' lines (minimal 2) at cursor position.
* When "save_undo" is TRUE save lines for undo first.
* Set "use_formatoptions" to FALSE when e.g. processing backspace and comment
* leaders should not be removed.
--- 1944,1950 ----
}

/*
! * Join 'count' lines (minimal 2) at the cursor position.
* When "save_undo" is TRUE save lines for undo first.
* Set "use_formatoptions" to FALSE when e.g. processing backspace and comment
* leaders should not be removed.
*** ../vim-9.0.0153/src/testdir/test_textprop.vim 2022-08-06 15:58:48.906928830 +0100
--- src/testdir/test_textprop.vim 2022-08-06 17:04:44.025453621 +0100
***************
*** 2450,2455 ****
--- 2450,2490 ----
call delete('XscriptPropsAfterNowrap')
endfunc

+ func Test_props_with_text_after_split_join()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ call setline(1, ['1122'])
+ call prop_type_add('belowprop', #{highlight: 'ErrorMsg'})
+ call prop_add(1, 0, #{type: 'belowprop', text: ' Below the line ', text_align: 'below'})
+ exe "normal f2i\<CR>\<Esc>"
+
+ func AddMore()
+ call prop_type_add('another', #{highlight: 'Search'})
+ call prop_add(1, 0, #{type: 'another', text: ' after the text ', text_align: 'after'})
+ call prop_add(1, 0, #{type: 'another', text: ' right here', text_align: 'right'})
+ endfunc
+ END
+ call writefile(lines, 'XscriptPropsAfterSplitJoin')
+ let buf = RunVimInTerminal('-S XscriptPropsAfterSplitJoin', #{rows: 8, cols: 60})
+ call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_1', {})
+
+ call term_sendkeys(buf, "ggJ")
+ call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_2', {})
+
+ call term_sendkeys(buf, ":call AddMore()\<CR>")
+ call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_3', {})
+
+ call term_sendkeys(buf, "ggf s\<CR>\<Esc>")
+ call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_4', {})
+
+ call term_sendkeys(buf, "ggJ")
+ call VerifyScreenDump(buf, 'Test_prop_with_text_after_join_split_5', {})
+
+ call StopVimInTerminal(buf)
+ call delete('XscriptPropsAfterSplitJoin')
+ endfunc
+
func Test_removed_prop_with_text_cleans_up_array()
new
call setline(1, 'some text here')
*** ../vim-9.0.0153/src/testdir/dumps/Test_prop_with_text_after_join_split_1.dump 2022-08-06 17:09:46.849158128 +0100
--- src/testdir/dumps/Test_prop_with_text_after_join_split_1.dump 2022-08-06 16:51:01.394088896 +0100
***************
*** 0 ****
--- 1,8 ----
+ |1+0&#ffffff0@1| @57
+ >2@1| @57
+ | +0#ffffff16#e000002|B|e|l|o|w| |t|h|e| |l|i|n|e| | +0#0000000#ffffff0@43
+ |~+0#4040ff13&| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ | +0#0000000&@41|2|,|1| @10|A|l@1|
*** ../vim-9.0.0153/src/testdir/dumps/Test_prop_with_text_after_join_split_2.dump 2022-08-06 17:09:46.857158121 +0100
--- src/testdir/dumps/Test_prop_with_text_after_join_split_2.dump 2022-08-06 16:54:10.209980709 +0100
***************
*** 0 ****
--- 1,8 ----
+ |1+0&#ffffff0@1> |2@1| @54
+ | +0#ffffff16#e000002|B|e|l|o|w| |t|h|e| |l|i|n|e| | +0#0000000#ffffff0@43
+ |~+0#4040ff13&| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ | +0#0000000&@41|1|,|3| @10|A|l@1|
*** ../vim-9.0.0153/src/testdir/dumps/Test_prop_with_text_after_join_split_3.dump 2022-08-06 17:09:46.861158118 +0100
--- src/testdir/dumps/Test_prop_with_text_after_join_split_3.dump 2022-08-06 17:04:48.093449766 +0100
***************
*** 0 ****
--- 1,8 ----
+ |1+0&#ffffff0@1> |2@1| +0&#ffff4012|a|f|t|e|r| |t|h|e| |t|e|x|t| | +0&#ffffff0@27| +0&#ffff4012|r|i|g|h|t| |h|e|r|e
+ | +0#ffffff16#e000002|B|e|l|o|w| |t|h|e| |l|i|n|e| | +0#0000000#ffffff0@43
+ |~+0#4040ff13&| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ |:+0#0000000&|c|a|l@1| |A|d@1|M|o|r|e|(|)| @26|1|,|3| @10|A|l@1|
*** ../vim-9.0.0153/src/testdir/dumps/Test_prop_with_text_after_join_split_4.dump 2022-08-06 17:09:46.865158112 +0100
--- src/testdir/dumps/Test_prop_with_text_after_join_split_4.dump 2022-08-06 17:04:49.241448680 +0100
***************
*** 0 ****
--- 1,8 ----
+ |1+0&#ffffff0@1| @57
+ >2@1| +0&#ffff4012|a|f|t|e|r| |t|h|e| |t|e|x|t| | +0&#ffffff0@30| +0&#ffff4012|r|i|g|h|t| |h|e|r|e
+ | +0#ffffff16#e000002|B|e|l|o|w| |t|h|e| |l|i|n|e| | +0#0000000#ffffff0@43
+ |~+0#4040ff13&| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ | +0#0000000&@41|2|,|1| @10|A|l@1|
*** ../vim-9.0.0153/src/testdir/dumps/Test_prop_with_text_after_join_split_5.dump 2022-08-06 17:09:46.869158108 +0100
--- src/testdir/dumps/Test_prop_with_text_after_join_split_5.dump 2022-08-06 17:04:50.393447586 +0100
***************
*** 0 ****
--- 1,8 ----
+ |1+0&#ffffff0@1> |2@1| +0&#ffff4012|a|f|t|e|r| |t|h|e| |t|e|x|t| | +0&#ffffff0@27| +0&#ffff4012|r|i|g|h|t| |h|e|r|e
+ | +0#ffffff16#e000002|B|e|l|o|w| |t|h|e| |l|i|n|e| | +0#0000000#ffffff0@43
+ |~+0#4040ff13&| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ |~| @58
+ | +0#0000000&@41|1|,|3| @10|A|l@1|
*** ../vim-9.0.0153/src/version.c 2022-08-06 15:58:48.906928830 +0100
--- src/version.c 2022-08-06 17:09:17.805187105 +0100
***************
*** 737,738 ****
--- 737,740 ----
{ /* Add new patch number below this line */
+ /**/
+ 154,
/**/

--
hundred-and-one symptoms of being an internet addict:
256. You are able to write down over 250 symptoms of being an internet
addict, even though they only asked for 101.

/// Bram Moolenaar -- Br...@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 ///
Reply all
Reply to author
Forward
0 new messages