Mercurial > vim
comparison src/drawline.c @ 34684:faf891660963 v9.1.0223
patch 9.1.0223: code duplication in loop to add active text properties
Commit: https://github.com/vim/vim/commit/1134fdd1b369119d0d6992e3120bb5f7c788b697
Author: Dylan Thacker-Smith <dylan.ah.smith@gmail.com>
Date: Thu Mar 28 11:49:46 2024 +0100
patch 9.1.0223: code duplication in loop to add active text properties
Problem: There are two dense conditions with duplication that needs to
be kept in sync between the while loop break condition and the
condition to skip certain text properties.
Solution: Refactor the loop by moving while loop conditions into the
body of the while loop so they can be shared with skip
conditions. `break` and an `active` variable are used to
handle the outcome of these merged conditions.
(Dylan Thacker-Smith)
closes: #14307
Signed-off-by: Dylan Thacker-Smith <dylan.ah.smith@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 28 Mar 2024 12:00:05 +0100 |
parents | a36144b38683 |
children | ffa6ed03a9f2 |
comparison
equal
deleted
inserted
replaced
34683:1bfa0faf0969 | 34684:faf891660963 |
---|---|
2071 if (wlv.n_extra > 0 && in_linebreak) | 2071 if (wlv.n_extra > 0 && in_linebreak) |
2072 // not on the next char yet, don't start another prop | 2072 // not on the next char yet, don't start another prop |
2073 --bcol; | 2073 --bcol; |
2074 # endif | 2074 # endif |
2075 // Add any text property that starts in this column. | 2075 // Add any text property that starts in this column. |
2076 while (text_prop_next < text_prop_count | 2076 while (text_prop_next < text_prop_count) |
2077 && (text_props[text_prop_next].tp_col == MAXCOL | 2077 { |
2078 ? (*ptr == NUL | 2078 int active; |
2079 || (bcol == 0 | 2079 textprop_T *tp = &text_props[text_prop_next]; |
2080 && (text_props[text_prop_next].tp_flags | 2080 if (tp->tp_col == MAXCOL) |
2081 & TP_FLAG_ALIGN_ABOVE))) | 2081 { |
2082 : bcol >= text_props[text_prop_next].tp_col - 1)) | 2082 if (bcol == 0 && (tp->tp_flags & TP_FLAG_ALIGN_ABOVE)) |
2083 { | 2083 active = TRUE; |
2084 // With 'nowrap' and not in the first screen line only "below" | 2084 else if (*ptr != NUL) |
2085 // text prop can show. | 2085 break; |
2086 if (text_props[text_prop_next].tp_col == MAXCOL | 2086 else |
2087 ? (wp->w_p_wrap | 2087 { |
2088 // With 'nowrap' and not in the first screen line only "below" | |
2089 // text prop can show. | |
2090 active = wp->w_p_wrap | |
2088 || wlv.row == startrow | 2091 || wlv.row == startrow |
2089 || (text_props[text_prop_next].tp_flags | 2092 || (tp->tp_flags & TP_FLAG_ALIGN_BELOW); |
2090 & TP_FLAG_ALIGN_BELOW) | 2093 } |
2091 || (bcol == 0 | 2094 } |
2092 && (text_props[text_prop_next].tp_flags | 2095 else |
2093 & TP_FLAG_ALIGN_ABOVE))) | 2096 { |
2094 : bcol <= text_props[text_prop_next].tp_col - 1 | 2097 if (bcol < tp->tp_col - 1) |
2095 + text_props[text_prop_next].tp_len) | 2098 break; |
2096 { | 2099 active = bcol <= tp->tp_col - 1 + tp->tp_len; |
2100 } | |
2101 | |
2102 if (active) | |
2097 text_prop_idxs[text_props_active++] = text_prop_next; | 2103 text_prop_idxs[text_props_active++] = text_prop_next; |
2098 } | |
2099 ++text_prop_next; | 2104 ++text_prop_next; |
2100 } | 2105 } |
2101 | 2106 |
2102 if (wlv.n_extra == 0 || | 2107 if (wlv.n_extra == 0 || |
2103 (!wlv.extra_for_textprop | 2108 (!wlv.extra_for_textprop |