comparison src/textprop.c @ 15341:03a7a9fdb792 v8.1.0678

patch 8.1.0678: text properties as not adjusted for inserted text commit https://github.com/vim/vim/commit/44746aa1eb506ebe6e8fc71f6e549a0dcb754526 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 2 00:02:11 2019 +0100 patch 8.1.0678: text properties as not adjusted for inserted text Problem: Text properties as not adjusted for inserted text. Solution: Adjust text properties when inserting text.
author Bram Moolenaar <Bram@vim.org>
date Wed, 02 Jan 2019 00:15:05 +0100
parents 18c20ceee4b5
children 6abee072b93c
comparison
equal deleted inserted replaced
15340:90d037c7fa06 15341:03a7a9fdb792
913 } 913 }
914 914
915 /* 915 /*
916 * Adjust the columns of text properties in line "lnum" after position "col" to 916 * Adjust the columns of text properties in line "lnum" after position "col" to
917 * shift by "bytes_added" (can be negative). 917 * shift by "bytes_added" (can be negative).
918 */ 918 * Note that "col" is zero-based, while tp_col is one-based.
919 void 919 * Only for the current buffer.
920 adjust_prop_columns(linenr_T lnum UNUSED, colnr_T col UNUSED, int bytes_added UNUSED) 920 * Called is expected to check b_has_textprop and "bytes_added" being non-zero.
921 { 921 */
922 // TODO 922 void
923 adjust_prop_columns(linenr_T lnum, colnr_T col, int bytes_added)
924 {
925 int proplen;
926 char_u *props;
927 textprop_T tmp_prop;
928 proptype_T *pt;
929 int dirty = FALSE;
930 int i;
931
932 proplen = get_text_props(curbuf, lnum, &props, TRUE);
933 if (proplen == 0)
934 return;
935
936 for (i = 0; i < proplen; ++i)
937 {
938 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T),
939 sizeof(textprop_T));
940 pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type);
941
942 if (tmp_prop.tp_col >= col + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL) ? 2 : 1))
943 {
944 tmp_prop.tp_col += bytes_added;
945 dirty = TRUE;
946 }
947 else if (tmp_prop.tp_col + tmp_prop.tp_len > col + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL) ? 0 : 1))
948 {
949 tmp_prop.tp_len += bytes_added;
950 dirty = TRUE;
951 }
952 if (dirty)
953 {
954 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
955 mch_memmove(props + i * sizeof(textprop_T), &tmp_prop,
956 sizeof(textprop_T));
957 }
958 }
923 } 959 }
924 960
925 #endif // FEAT_TEXT_PROP 961 #endif // FEAT_TEXT_PROP