Mercurial > vim
comparison src/drawline.c @ 29597:f2d7f20d83c3 v9.0.0139
patch 9.0.0139: truncating virtual text after a line not implemented
Commit: https://github.com/vim/vim/commit/398649ee44edeb309c77361de697320378104b70
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 4 15:03:48 2022 +0100
patch 9.0.0139: truncating virtual text after a line not implemented
Problem: Truncating virtual text after a line not implemented.
Cursor positioning wrong with Newline in the text.
Solution: Implement truncating. Disallow control characters in the text.
(closes #10842)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 04 Aug 2022 16:15:08 +0200 |
parents | 32aee589fc9a |
children | 608d5221a3e5 |
comparison
equal
deleted
inserted
replaced
29596:aea558552904 | 29597:f2d7f20d83c3 |
---|---|
1552 { | 1552 { |
1553 int right = (text_props[used_tpi].tp_flags | 1553 int right = (text_props[used_tpi].tp_flags |
1554 & TP_FLAG_ALIGN_RIGHT); | 1554 & TP_FLAG_ALIGN_RIGHT); |
1555 int below = (text_props[used_tpi].tp_flags | 1555 int below = (text_props[used_tpi].tp_flags |
1556 & TP_FLAG_ALIGN_BELOW); | 1556 & TP_FLAG_ALIGN_BELOW); |
1557 int wrap = (text_props[used_tpi].tp_flags | |
1558 & TP_FLAG_WRAP); | |
1557 | 1559 |
1558 p_extra = p; | 1560 p_extra = p; |
1559 c_extra = NUL; | 1561 c_extra = NUL; |
1560 c_final = NUL; | 1562 c_final = NUL; |
1561 n_extra = (int)STRLEN(p); | 1563 n_extra = (int)STRLEN(p); |
1564 text_prop_attr = 0; | 1566 text_prop_attr = 0; |
1565 if (*ptr == NUL) | 1567 if (*ptr == NUL) |
1566 // don't combine char attr after EOL | 1568 // don't combine char attr after EOL |
1567 text_prop_combine = FALSE; | 1569 text_prop_combine = FALSE; |
1568 | 1570 |
1569 // TODO: truncation if it doesn't fit | 1571 // Keep in sync with where |
1570 if (right || below) | 1572 // textprop_size_after_trunc() is called in |
1573 // win_lbr_chartabsize(). | |
1574 if ((right || below || !wrap) && wp->w_width > 2) | |
1571 { | 1575 { |
1572 int added = wp->w_width - col; | 1576 int added = wp->w_width - col; |
1577 int n_used = n_extra; | |
1573 char_u *l; | 1578 char_u *l; |
1574 | 1579 int strsize = wrap |
1575 // Right-align: fill with spaces | 1580 ? vim_strsize(p_extra) |
1576 if (right) | 1581 : textprop_size_after_trunc(wp, |
1577 added -= vim_strsize(p_extra); | 1582 below, added, p_extra, &n_used); |
1578 if (added < 0 || (below && col == 0)) | 1583 |
1579 added = 0; | 1584 if (wrap || right || below || n_used < n_extra) |
1580 l = alloc(n_extra + added + 1); | |
1581 if (l != NULL) | |
1582 { | 1585 { |
1583 vim_memset(l, ' ', added); | 1586 // Right-align: fill with spaces |
1584 STRCPY(l + added, p); | 1587 if (right) |
1585 vim_free(p_extra_free); | 1588 added -= strsize; |
1586 p_extra = p_extra_free = l; | 1589 if (added < 0 || (below && col == 0) |
1587 n_extra += added; | 1590 || (!below && n_used < n_extra)) |
1588 n_attr_skip = added; | 1591 added = 0; |
1592 // add 1 for NUL, 2 for when '…' is used | |
1593 l = alloc(n_used + added + 3); | |
1594 if (l != NULL) | |
1595 { | |
1596 vim_memset(l, ' ', added); | |
1597 vim_strncpy(l + added, p_extra, n_used); | |
1598 if (n_used < n_extra) | |
1599 { | |
1600 char_u *lp = l + added + n_used - 1; | |
1601 | |
1602 if (has_mbyte) | |
1603 { | |
1604 // change last character to '…' | |
1605 lp -= (*mb_head_off)(l, lp); | |
1606 STRCPY(lp, "…"); | |
1607 n_used = lp - l + 3; | |
1608 } | |
1609 else | |
1610 // change last character to '>' | |
1611 *lp = '>'; | |
1612 } | |
1613 vim_free(p_extra_free); | |
1614 p_extra = p_extra_free = l; | |
1615 n_extra = n_used + added; | |
1616 n_attr_skip = added; | |
1617 } | |
1589 } | 1618 } |
1590 } | 1619 } |
1591 } | 1620 } |
1592 // reset the ID in the copy to avoid it being used | 1621 // reset the ID in the copy to avoid it being used |
1593 // again | 1622 // again |
1596 // If another text prop follows the condition below at | 1625 // If another text prop follows the condition below at |
1597 // the last window column must know. | 1626 // the last window column must know. |
1598 text_prop_follows = other_tpi != -1; | 1627 text_prop_follows = other_tpi != -1; |
1599 } | 1628 } |
1600 } | 1629 } |
1630 else if (text_prop_next < text_prop_count | |
1631 && text_props[text_prop_next].tp_col == MAXCOL | |
1632 && *ptr != NUL | |
1633 && ptr[mb_ptr2len(ptr)] == NUL) | |
1634 // When at last-but-one character and a text property | |
1635 // follows after it, we may need to flush the line after | |
1636 // displaying that character. | |
1637 text_prop_follows = TRUE; | |
1601 } | 1638 } |
1602 #endif | 1639 #endif |
1603 | 1640 |
1604 #ifdef FEAT_SYN_HL | 1641 #ifdef FEAT_SYN_HL |
1605 if (extra_check && n_extra == 0) | 1642 if (extra_check && n_extra == 0) |