comparison src/textprop.c @ 15349:6abee072b93c v8.1.0682

patch 8.1.0682: text properties not adjusted when backspacing replaced text commit https://github.com/vim/vim/commit/196d157f12cf0476d97f78834155fc67d6b161de Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 2 23:47:18 2019 +0100 patch 8.1.0682: text properties not adjusted when backspacing replaced text Problem: Text properties are not adjusted when backspacing replaced text. Solution: Keep text properties on text restored in replace mode.
author Bram Moolenaar <Bram@vim.org>
date Thu, 03 Jan 2019 00:00:54 +0100
parents 03a7a9fdb792
children 21580db06cf3
comparison
equal deleted inserted replaced
15348:24c31bd03f3a 15349:6abee072b93c
918 * Note that "col" is zero-based, while tp_col is one-based. 918 * Note that "col" is zero-based, while tp_col is one-based.
919 * Only for the current buffer. 919 * Only for the current buffer.
920 * Called is expected to check b_has_textprop and "bytes_added" being non-zero. 920 * Called is expected to check b_has_textprop and "bytes_added" being non-zero.
921 */ 921 */
922 void 922 void
923 adjust_prop_columns(linenr_T lnum, colnr_T col, int bytes_added) 923 adjust_prop_columns(
924 linenr_T lnum,
925 colnr_T col,
926 int bytes_added)
924 { 927 {
925 int proplen; 928 int proplen;
926 char_u *props; 929 char_u *props;
927 textprop_T tmp_prop; 930 textprop_T tmp_prop;
928 proptype_T *pt; 931 proptype_T *pt;
929 int dirty = FALSE; 932 int dirty = FALSE;
930 int i; 933 int ri, wi;
934 size_t textlen;
935
936 if (text_prop_frozen > 0)
937 return;
931 938
932 proplen = get_text_props(curbuf, lnum, &props, TRUE); 939 proplen = get_text_props(curbuf, lnum, &props, TRUE);
933 if (proplen == 0) 940 if (proplen == 0)
934 return; 941 return;
935 942 textlen = curbuf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
936 for (i = 0; i < proplen; ++i) 943
937 { 944 wi = 0; // write index
938 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T), 945 for (ri = 0; ri < proplen; ++ri)
946 {
947 mch_memmove(&tmp_prop, props + ri * sizeof(textprop_T),
939 sizeof(textprop_T)); 948 sizeof(textprop_T));
940 pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type); 949 pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type);
941 950
942 if (tmp_prop.tp_col >= col + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL) ? 2 : 1)) 951 if (bytes_added > 0
952 ? (tmp_prop.tp_col >= col + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL) ? 2 : 1))
953 : (tmp_prop.tp_col > col + 1))
943 { 954 {
944 tmp_prop.tp_col += bytes_added; 955 tmp_prop.tp_col += bytes_added;
945 dirty = TRUE; 956 dirty = TRUE;
946 } 957 }
947 else if (tmp_prop.tp_col + tmp_prop.tp_len > col + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL) ? 0 : 1)) 958 else if (tmp_prop.tp_len > 0
959 && tmp_prop.tp_col + tmp_prop.tp_len > col
960 + ((pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL))
961 ? 0 : 1))
948 { 962 {
949 tmp_prop.tp_len += bytes_added; 963 tmp_prop.tp_len += bytes_added;
950 dirty = TRUE; 964 dirty = TRUE;
951 } 965 if (tmp_prop.tp_len <= 0)
952 if (dirty) 966 continue; // drop this text property
953 { 967 }
954 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY; 968 mch_memmove(props + wi * sizeof(textprop_T), &tmp_prop,
955 mch_memmove(props + i * sizeof(textprop_T), &tmp_prop,
956 sizeof(textprop_T)); 969 sizeof(textprop_T));
957 } 970 ++wi;
971 }
972 if (dirty)
973 {
974 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
975 curbuf->b_ml.ml_line_len = textlen + wi * sizeof(textprop_T);
958 } 976 }
959 } 977 }
960 978
961 #endif // FEAT_TEXT_PROP 979 #endif // FEAT_TEXT_PROP