diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-01-02 00:02:11 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-01-02 00:02:11 +0100 |
commit | 44746aa1eb506ebe6e8fc71f6e549a0dcb754526 (patch) | |
tree | 4da24442545c3971d29668a78d354288e3fc1c90 /src/textprop.c | |
parent | 866f3558141aa68862aa2fedbb7747bf2365e838 (diff) | |
download | vim-git-44746aa1eb506ebe6e8fc71f6e549a0dcb754526.tar.gz |
patch 8.1.0678: text properties as not adjusted for inserted textv8.1.0678
Problem: Text properties as not adjusted for inserted text.
Solution: Adjust text properties when inserting text.
Diffstat (limited to 'src/textprop.c')
-rw-r--r-- | src/textprop.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/textprop.c b/src/textprop.c index ce6b66c28..526a6f0a1 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -915,11 +915,47 @@ clear_buf_prop_types(buf_T *buf) /* * Adjust the columns of text properties in line "lnum" after position "col" to * shift by "bytes_added" (can be negative). + * Note that "col" is zero-based, while tp_col is one-based. + * Only for the current buffer. + * Called is expected to check b_has_textprop and "bytes_added" being non-zero. */ void -adjust_prop_columns(linenr_T lnum UNUSED, colnr_T col UNUSED, int bytes_added UNUSED) +adjust_prop_columns(linenr_T lnum, colnr_T col, int bytes_added) { - // TODO + int proplen; + char_u *props; + textprop_T tmp_prop; + proptype_T *pt; + int dirty = FALSE; + int i; + + proplen = get_text_props(curbuf, lnum, &props, TRUE); + if (proplen == 0) + return; + + for (i = 0; i < proplen; ++i) + { + mch_memmove(&tmp_prop, props + i * sizeof(textprop_T), + sizeof(textprop_T)); + pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type); + + if (tmp_prop.tp_col >= col + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL) ? 2 : 1)) + { + tmp_prop.tp_col += bytes_added; + dirty = TRUE; + } + else if (tmp_prop.tp_col + tmp_prop.tp_len > col + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL) ? 0 : 1)) + { + tmp_prop.tp_len += bytes_added; + dirty = TRUE; + } + if (dirty) + { + curbuf->b_ml.ml_flags |= ML_LINE_DIRTY; + mch_memmove(props + i * sizeof(textprop_T), &tmp_prop, + sizeof(textprop_T)); + } + } } #endif // FEAT_TEXT_PROP |