Mercurial > vim
comparison src/textprop.c @ 29748:7e2321707fea v9.0.0214
patch 9.0.0214: splitting a line may duplicate virtual text
Commit: https://github.com/vim/vim/commit/d8d4cfcb393123fa19640be0806091d47935407f
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Aug 15 15:55:10 2022 +0100
patch 9.0.0214: splitting a line may duplicate virtual text
Problem: Splitting a line may duplicate virtual text. (Ben Jackson)
Solution: Don't duplicate a text property with virtual text. Make
auto-indenting work better. (closes #10919)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 15 Aug 2022 17:00:06 +0200 |
parents | 89e1d67814a9 |
children | d08aa1bfe319 |
comparison
equal
deleted
inserted
replaced
29747:5a91d76d1813 | 29748:7e2321707fea |
---|---|
1904 * | 1904 * |
1905 * Note that "col" is zero-based, while tp_col is one-based. | 1905 * Note that "col" is zero-based, while tp_col is one-based. |
1906 * Only for the current buffer. | 1906 * Only for the current buffer. |
1907 * "flags" can have: | 1907 * "flags" can have: |
1908 * APC_SUBSTITUTE: Text is replaced, not inserted. | 1908 * APC_SUBSTITUTE: Text is replaced, not inserted. |
1909 * APC_INDENT: Text is inserted before virtual text prop | |
1909 */ | 1910 */ |
1910 static adjustres_T | 1911 static adjustres_T |
1911 adjust_prop( | 1912 adjust_prop( |
1912 textprop_T *prop, | 1913 textprop_T *prop, |
1913 colnr_T col, | 1914 colnr_T col, |
1929 | 1930 |
1930 pt = text_prop_type_by_id(curbuf, prop->tp_type); | 1931 pt = text_prop_type_by_id(curbuf, prop->tp_type); |
1931 start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)) | 1932 start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)) |
1932 || (flags & APC_SUBSTITUTE) | 1933 || (flags & APC_SUBSTITUTE) |
1933 || (prop->tp_flags & TP_FLAG_CONT_PREV); | 1934 || (prop->tp_flags & TP_FLAG_CONT_PREV); |
1935 if (prop->tp_id < 0 && (flags & APC_INDENT)) | |
1936 // when inserting indent just before a character with virtual text | |
1937 // shift the text property | |
1938 start_incl = FALSE; | |
1934 end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL)) | 1939 end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL)) |
1935 || (prop->tp_flags & TP_FLAG_CONT_NEXT); | 1940 || (prop->tp_flags & TP_FLAG_CONT_NEXT); |
1936 // do not drop zero-width props if they later can increase in size | 1941 // do not drop zero-width props if they later can increase in size |
1937 droppable = !(start_incl || end_incl); | 1942 droppable = !(start_incl || end_incl); |
1938 | 1943 |
1980 * Note that "col" is zero-based, while tp_col is one-based. | 1985 * Note that "col" is zero-based, while tp_col is one-based. |
1981 * Only for the current buffer. | 1986 * Only for the current buffer. |
1982 * "flags" can have: | 1987 * "flags" can have: |
1983 * APC_SAVE_FOR_UNDO: Call u_savesub() before making changes to the line. | 1988 * APC_SAVE_FOR_UNDO: Call u_savesub() before making changes to the line. |
1984 * APC_SUBSTITUTE: Text is replaced, not inserted. | 1989 * APC_SUBSTITUTE: Text is replaced, not inserted. |
1990 * APC_INDENT: Text is inserted before virtual text prop | |
1985 * Caller is expected to check b_has_textprop and "bytes_added" being non-zero. | 1991 * Caller is expected to check b_has_textprop and "bytes_added" being non-zero. |
1986 * Returns TRUE when props were changed. | 1992 * Returns TRUE when props were changed. |
1987 */ | 1993 */ |
1988 int | 1994 int |
1989 adjust_prop_columns( | 1995 adjust_prop_columns( |
2095 start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)); | 2101 start_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)); |
2096 end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL)); | 2102 end_incl = (pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL)); |
2097 cont_prev = prop.tp_col != MAXCOL && prop.tp_col + !start_incl <= kept; | 2103 cont_prev = prop.tp_col != MAXCOL && prop.tp_col + !start_incl <= kept; |
2098 cont_next = prop.tp_col != MAXCOL | 2104 cont_next = prop.tp_col != MAXCOL |
2099 && skipped <= prop.tp_col + prop.tp_len - !end_incl; | 2105 && skipped <= prop.tp_col + prop.tp_len - !end_incl; |
2106 // when a prop has text it is never copied | |
2107 if (prop.tp_id < 0 && cont_next) | |
2108 cont_prev = FALSE; | |
2100 | 2109 |
2101 if (cont_prev && ga_grow(&prevprop, 1) == OK) | 2110 if (cont_prev && ga_grow(&prevprop, 1) == OK) |
2102 { | 2111 { |
2103 textprop_T *p = ((textprop_T *)prevprop.ga_data) + prevprop.ga_len; | 2112 textprop_T *p = ((textprop_T *)prevprop.ga_data) + prevprop.ga_len; |
2104 | 2113 |