summaryrefslogtreecommitdiffstats
path: root/src/textprop.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-08-05 19:46:48 +0100
committerBram Moolenaar <Bram@vim.org>2022-08-05 19:46:48 +0100
commit213bbaf15afc628e5f83d1ae6526631ca8292292 (patch)
treef9b701acce08e848d8b8dde47946ab32a1b22b54 /src/textprop.c
parentf4ba8bc47eb3c6b5899ef31d083b9b8f0d4ca456 (diff)
patch 9.0.0145: substitute that joins lines drops text propertiesv9.0.0145
Problem: Substitute that joins lines drops text properties. Solution: Move text properties of the last line to the new line.
Diffstat (limited to 'src/textprop.c')
-rw-r--r--src/textprop.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/textprop.c b/src/textprop.c
index 86b0dbf883..9e643f7185 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -12,7 +12,6 @@
*
* TODO:
* - Adjust text property column and length when text is inserted/deleted.
- * -> a :substitute with a multi-line match
* -> search for changed_bytes() from misc1.c
* -> search for mark_col_adjust()
* - Perhaps we only need TP_FLAG_CONT_NEXT and can drop TP_FLAG_CONT_PREV?
@@ -683,6 +682,29 @@ set_text_props(linenr_T lnum, char_u *props, int len)
curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
}
+/*
+ * 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)
+{
+ char_u *text;
+ char_u *newtext;
+ int proplen = text_prop_count * (int)sizeof(textprop_T);
+
+ text = ml_get(lnum);
+ newtext = alloc(curbuf->b_ml.ml_line_len + proplen);
+ if (newtext == NULL)
+ return;
+ mch_memmove(newtext, text, curbuf->b_ml.ml_line_len);
+ mch_memmove(newtext + curbuf->b_ml.ml_line_len, text_props, proplen);
+ if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED))
+ vim_free(curbuf->b_ml.ml_line_ptr);
+ curbuf->b_ml.ml_line_ptr = newtext;
+ curbuf->b_ml.ml_line_len += proplen;
+ curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
+}
+
static proptype_T *
find_type_by_id(hashtab_T *ht, int id)
{