Mercurial > vim
comparison src/textprop.c @ 16714:ba592f30c082 v8.1.1359
patch 8.1.1359: text property wrong after :substitute with backslash
commit https://github.com/vim/vim/commit/f3333b02f34526da46cdae608f7e2d869bb8c654
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 19 22:53:40 2019 +0200
patch 8.1.1359: text property wrong after :substitute with backslash
Problem: Text property wrong after :substitute with backslash.
Solution: Adjust text property columns when removing backslashes.
(closes #4397)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 19 May 2019 23:00:05 +0200 |
parents | 23af483c4ceb |
children | 75703a39d875 |
comparison
equal
deleted
inserted
replaced
16713:ba3f15a7e5c9 | 16714:ba592f30c082 |
---|---|
955 /* | 955 /* |
956 * Adjust the columns of text properties in line "lnum" after position "col" to | 956 * Adjust the columns of text properties in line "lnum" after position "col" to |
957 * shift by "bytes_added" (can be negative). | 957 * shift by "bytes_added" (can be negative). |
958 * Note that "col" is zero-based, while tp_col is one-based. | 958 * Note that "col" is zero-based, while tp_col is one-based. |
959 * Only for the current buffer. | 959 * Only for the current buffer. |
960 * When "save_for_undo" is TRUE then call u_savesub() before making changes to | 960 * "flags" can have: |
961 * the line. | 961 * APC_SAVE_FOR_UNDO: Call u_savesub() before making changes to the line. |
962 * APC_SUBSTITUTE: Text is replaced, not inserted. | |
962 * Caller is expected to check b_has_textprop and "bytes_added" being non-zero. | 963 * Caller is expected to check b_has_textprop and "bytes_added" being non-zero. |
963 * Returns TRUE when props were changed. | 964 * Returns TRUE when props were changed. |
964 */ | 965 */ |
965 int | 966 int |
966 adjust_prop_columns( | 967 adjust_prop_columns( |
967 linenr_T lnum, | 968 linenr_T lnum, |
968 colnr_T col, | 969 colnr_T col, |
969 int bytes_added, | 970 int bytes_added, |
970 int save_for_undo) | 971 int flags) |
971 { | 972 { |
972 int proplen; | 973 int proplen; |
973 char_u *props; | 974 char_u *props; |
974 textprop_T tmp_prop; | 975 textprop_T tmp_prop; |
975 proptype_T *pt; | 976 proptype_T *pt; |
986 textlen = curbuf->b_ml.ml_line_len - proplen * sizeof(textprop_T); | 987 textlen = curbuf->b_ml.ml_line_len - proplen * sizeof(textprop_T); |
987 | 988 |
988 wi = 0; // write index | 989 wi = 0; // write index |
989 for (ri = 0; ri < proplen; ++ri) | 990 for (ri = 0; ri < proplen; ++ri) |
990 { | 991 { |
992 int start_incl; | |
993 | |
991 mch_memmove(&tmp_prop, props + ri * sizeof(textprop_T), | 994 mch_memmove(&tmp_prop, props + ri * sizeof(textprop_T), |
992 sizeof(textprop_T)); | 995 sizeof(textprop_T)); |
993 pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type); | 996 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)); | |
994 | 999 |
995 if (bytes_added > 0 | 1000 if (bytes_added > 0 |
996 ? (tmp_prop.tp_col >= col | 1001 && (tmp_prop.tp_col >= col + (start_incl ? 2 : 1))) |
997 + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL) | 1002 { |
998 ? 2 : 1)) | 1003 if (tmp_prop.tp_col < col + (start_incl ? 2 : 1)) |
999 : (tmp_prop.tp_col > col + 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)) | |
1000 { | 1016 { |
1001 if (tmp_prop.tp_col + bytes_added < col + 1) | 1017 if (tmp_prop.tp_col + bytes_added < col + 1) |
1002 { | 1018 { |
1003 tmp_prop.tp_len += (tmp_prop.tp_col - 1 - col) + bytes_added; | 1019 tmp_prop.tp_len += (tmp_prop.tp_col - 1 - col) + bytes_added; |
1004 tmp_prop.tp_col = col + 1; | 1020 tmp_prop.tp_col = col + 1; |
1005 } | 1021 } |
1006 else | 1022 else |
1007 tmp_prop.tp_col += bytes_added; | 1023 tmp_prop.tp_col += bytes_added; |
1008 // Save for undo if requested and not done yet. | 1024 // Save for undo if requested and not done yet. |
1009 if (save_for_undo && !dirty) | 1025 if ((flags & APC_SAVE_FOR_UNDO) && !dirty) |
1010 u_savesub(lnum); | 1026 u_savesub(lnum); |
1011 dirty = TRUE; | 1027 dirty = TRUE; |
1012 if (tmp_prop.tp_len <= 0) | 1028 if (tmp_prop.tp_len <= 0) |
1013 continue; // drop this text property | 1029 continue; // drop this text property |
1014 } | 1030 } |
1022 if (after > 0) | 1038 if (after > 0) |
1023 tmp_prop.tp_len += bytes_added + after; | 1039 tmp_prop.tp_len += bytes_added + after; |
1024 else | 1040 else |
1025 tmp_prop.tp_len += bytes_added; | 1041 tmp_prop.tp_len += bytes_added; |
1026 // Save for undo if requested and not done yet. | 1042 // Save for undo if requested and not done yet. |
1027 if (save_for_undo && !dirty) | 1043 if ((flags & APC_SAVE_FOR_UNDO) && !dirty) |
1028 u_savesub(lnum); | 1044 u_savesub(lnum); |
1029 dirty = TRUE; | 1045 dirty = TRUE; |
1030 if (tmp_prop.tp_len <= 0) | 1046 if (tmp_prop.tp_len <= 0) |
1031 continue; // drop this text property | 1047 continue; // drop this text property |
1032 } | 1048 } |