@@ -957,8 +957,9 @@ clear_buf_prop_types(buf_T *buf)
957957 * shift by "bytes_added" (can be negative).
958958 * Note that "col" is zero-based, while tp_col is one-based.
959959 * Only for the current buffer.
960- * When "save_for_undo" is TRUE then call u_savesub() before making changes to
961- * the line.
960+ * "flags" can have:
961+ * APC_SAVE_FOR_UNDO: Call u_savesub() before making changes to the line.
962+ * APC_SUBSTITUTE: Text is replaced, not inserted.
962963 * Caller is expected to check b_has_textprop and "bytes_added" being non-zero.
963964 * Returns TRUE when props were changed.
964965 */
@@ -967,7 +968,7 @@ adjust_prop_columns(
967968 linenr_T lnum ,
968969 colnr_T col ,
969970 int bytes_added ,
970- int save_for_undo )
971+ int flags )
971972{
972973 int proplen ;
973974 char_u * props ;
@@ -988,15 +989,30 @@ adjust_prop_columns(
988989 wi = 0 ; // write index
989990 for (ri = 0 ; ri < proplen ; ++ ri )
990991 {
992+ int start_incl ;
993+
991994 mch_memmove (& tmp_prop , props + ri * sizeof (textprop_T ),
992995 sizeof (textprop_T ));
993996 pt = text_prop_type_by_id (curbuf , tmp_prop .tp_type );
997+ start_incl = (flags & APC_SUBSTITUTE ) ||
998+ (pt != NULL && (pt -> pt_flags & PT_FLAG_INS_START_INCL ));
994999
9951000 if (bytes_added > 0
996- ? (tmp_prop .tp_col >= col
997- + (pt != NULL && (pt -> pt_flags & PT_FLAG_INS_START_INCL )
998- ? 2 : 1 ))
999- : (tmp_prop .tp_col > col + 1 ))
1001+ && (tmp_prop .tp_col >= col + (start_incl ? 2 : 1 )))
1002+ {
1003+ if (tmp_prop .tp_col < col + (start_incl ? 2 : 1 ))
1004+ {
1005+ tmp_prop .tp_len += (tmp_prop .tp_col - 1 - col ) + bytes_added ;
1006+ tmp_prop .tp_col = col + 1 ;
1007+ }
1008+ else
1009+ tmp_prop .tp_col += bytes_added ;
1010+ // Save for undo if requested and not done yet.
1011+ if ((flags & APC_SAVE_FOR_UNDO ) && !dirty )
1012+ u_savesub (lnum );
1013+ dirty = TRUE;
1014+ }
1015+ else if (bytes_added <= 0 && (tmp_prop .tp_col > col + 1 ))
10001016 {
10011017 if (tmp_prop .tp_col + bytes_added < col + 1 )
10021018 {
@@ -1006,7 +1022,7 @@ adjust_prop_columns(
10061022 else
10071023 tmp_prop .tp_col += bytes_added ;
10081024 // Save for undo if requested and not done yet.
1009- if (save_for_undo && !dirty )
1025+ if (( flags & APC_SAVE_FOR_UNDO ) && !dirty )
10101026 u_savesub (lnum );
10111027 dirty = TRUE;
10121028 if (tmp_prop .tp_len <= 0 )
@@ -1024,7 +1040,7 @@ adjust_prop_columns(
10241040 else
10251041 tmp_prop .tp_len += bytes_added ;
10261042 // Save for undo if requested and not done yet.
1027- if (save_for_undo && !dirty )
1043+ if (( flags & APC_SAVE_FOR_UNDO ) && !dirty )
10281044 u_savesub (lnum );
10291045 dirty = TRUE;
10301046 if (tmp_prop .tp_len <= 0 )
0 commit comments