Mercurial > vim
comparison src/charset.c @ 29676:b4fea827c20a v9.0.0178
patch 9.0.0178: cursor position wrong with virtual text before Tab
Commit: https://github.com/vim/vim/commit/e428fa04a758cc87ea580c856a796e58e407504b
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 9 16:55:41 2022 +0100
patch 9.0.0178: cursor position wrong with virtual text before Tab
Problem: Cursor position wrong with virtual text before Tab.
Solution: Use the byte length, not the cell with, to compare the column.
Correct tab size after text prop. (closes #10866)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 09 Aug 2022 18:00:03 +0200 |
parents | 53e434838a85 |
children | fc0f93590fd4 |
comparison
equal
deleted
inserted
replaced
29675:51b072a13be4 | 29676:b4fea827c20a |
---|---|
1128 size = win_chartabsize(wp, s, vcol); | 1128 size = win_chartabsize(wp, s, vcol); |
1129 | 1129 |
1130 # ifdef FEAT_PROP_POPUP | 1130 # ifdef FEAT_PROP_POPUP |
1131 if (cts->cts_has_prop_with_text && *line != NUL) | 1131 if (cts->cts_has_prop_with_text && *line != NUL) |
1132 { | 1132 { |
1133 int normal_size = size; | 1133 int tab_size = size; |
1134 int charlen = mb_ptr2len(s); | |
1134 int i; | 1135 int i; |
1135 int col = (int)(s - line); | 1136 int col = (int)(s - line); |
1136 garray_T *gap = &wp->w_buffer->b_textprop_text; | 1137 garray_T *gap = &wp->w_buffer->b_textprop_text; |
1137 | 1138 |
1138 for (i = 0; i < cts->cts_text_prop_count; ++i) | 1139 for (i = 0; i < cts->cts_text_prop_count; ++i) |
1141 | 1142 |
1142 // Watch out for the text being deleted. "cts_text_props" is a | 1143 // Watch out for the text being deleted. "cts_text_props" is a |
1143 // copy, the text prop may actually have been removed from the line. | 1144 // copy, the text prop may actually have been removed from the line. |
1144 if (tp->tp_id < 0 | 1145 if (tp->tp_id < 0 |
1145 && ((tp->tp_col - 1 >= col | 1146 && ((tp->tp_col - 1 >= col |
1146 && tp->tp_col - 1 < col + normal_size) | 1147 && tp->tp_col - 1 < col + charlen) |
1147 || (tp->tp_col == MAXCOL && (s[0] == NUL || s[1] == NUL) | 1148 || (tp->tp_col == MAXCOL && (s[0] == NUL || s[1] == NUL) |
1148 && cts->cts_with_trailing)) | 1149 && cts->cts_with_trailing)) |
1149 && -tp->tp_id - 1 < gap->ga_len) | 1150 && -tp->tp_id - 1 < gap->ga_len) |
1150 { | 1151 { |
1151 char_u *p = ((char_u **)gap->ga_data)[-tp->tp_id - 1]; | 1152 char_u *p = ((char_u **)gap->ga_data)[-tp->tp_id - 1]; |
1177 no_sbr = TRUE; // don't use 'showbreak' now | 1178 no_sbr = TRUE; // don't use 'showbreak' now |
1178 #endif | 1179 #endif |
1179 } | 1180 } |
1180 cts->cts_cur_text_width += cells; | 1181 cts->cts_cur_text_width += cells; |
1181 size += cells; | 1182 size += cells; |
1183 if (*s == TAB) | |
1184 { | |
1185 // tab size changes because of the inserted text | |
1186 size -= tab_size; | |
1187 tab_size = win_chartabsize(wp, s, vcol + size); | |
1188 size += tab_size; | |
1189 } | |
1182 } | 1190 } |
1183 } | 1191 } |
1184 if (tp->tp_col != MAXCOL && tp->tp_col - 1 > col) | 1192 if (tp->tp_col != MAXCOL && tp->tp_col - 1 > col) |
1185 break; | 1193 break; |
1186 } | 1194 } |
1523 *start = vcol + head; | 1531 *start = vcol + head; |
1524 if (end != NULL) | 1532 if (end != NULL) |
1525 *end = vcol + incr - 1; | 1533 *end = vcol + incr - 1; |
1526 if (cursor != NULL) | 1534 if (cursor != NULL) |
1527 { | 1535 { |
1528 #ifdef FEAT_PROP_POPUP | |
1529 if ((State & MODE_INSERT) == 0) | |
1530 // cursor is after inserted text | |
1531 vcol += cts.cts_cur_text_width; | |
1532 #endif | |
1533 if (*ptr == TAB | 1536 if (*ptr == TAB |
1534 && (State & MODE_NORMAL) | 1537 && (State & MODE_NORMAL) |
1535 && !wp->w_p_list | 1538 && !wp->w_p_list |
1536 && !virtual_active() | 1539 && !virtual_active() |
1537 && !(VIsual_active | 1540 && !(VIsual_active |
1538 && (*p_sel == 'e' || LTOREQ_POS(*pos, VIsual))) | 1541 && (*p_sel == 'e' || LTOREQ_POS(*pos, VIsual))) |
1539 ) | 1542 ) |
1540 *cursor = vcol + incr - 1; // cursor at end | 1543 *cursor = vcol + incr - 1; // cursor at end |
1541 else | 1544 else |
1545 { | |
1546 #ifdef FEAT_PROP_POPUP | |
1547 if ((State & MODE_INSERT) == 0) | |
1548 // cursor is after inserted text | |
1549 vcol += cts.cts_cur_text_width; | |
1550 #endif | |
1542 *cursor = vcol + head; // cursor at start | 1551 *cursor = vcol + head; // cursor at start |
1552 } | |
1543 } | 1553 } |
1544 } | 1554 } |
1545 | 1555 |
1546 /* | 1556 /* |
1547 * Get virtual cursor column in the current window, pretending 'list' is off. | 1557 * Get virtual cursor column in the current window, pretending 'list' is off. |