aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/drawline.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-10-12 06:49:11 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-10-12 07:02:49 +0800
commitdac79b165dfc3a576b3b33d82b9c5edae7b6ebd8 (patch)
treeea3f18c80fc50c29d625d71e3b369651c903132d /src/nvim/drawline.c
parent7474874baa3ea960fab38b66db36870b797afd5b (diff)
downloadrneovim-dac79b165dfc3a576b3b33d82b9c5edae7b6ebd8.tar.gz
rneovim-dac79b165dfc3a576b3b33d82b9c5edae7b6ebd8.tar.bz2
rneovim-dac79b165dfc3a576b3b33d82b9c5edae7b6ebd8.zip
vim-patch:9.0.2017: linebreak applies for leading whitespace
Problem: linebreak applies for leading whitespace Solution: only apply linebreak, once we have found non-breakat chars in the line closes: vim/vim#13228 closes: vim/vim#13243 https://github.com/vim/vim/commit/dd75fcfbdff1934c6e531b5a89ebc636318bf4a2 Co-authored-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/nvim/drawline.c')
-rw-r--r--src/nvim/drawline.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c
index 2d450087fd..1c7f649848 100644
--- a/src/nvim/drawline.c
+++ b/src/nvim/drawline.c
@@ -127,6 +127,9 @@ typedef struct {
int filler_lines; ///< nr of filler lines to be drawn
int filler_todo; ///< nr of filler lines still to do + 1
SignTextAttrs sattrs[SIGN_SHOW_MAX]; ///< sign attributes for the sign column
+ /// do consider wrapping in linebreak mode only after encountering
+ /// a non whitespace char
+ bool need_lbr;
VirtText virt_inline;
size_t virt_inline_i;
@@ -1018,6 +1021,7 @@ static void win_line_start(win_T *wp, winlinevars_T *wlv, bool save_extra)
{
wlv->col = 0;
wlv->off = 0;
+ wlv->need_lbr = false;
if (wp->w_p_rl) {
// Rightleft window: process the text in the normal direction, but put
@@ -1038,6 +1042,7 @@ static void win_line_start(win_T *wp, winlinevars_T *wlv, bool save_extra)
wlv->saved_extra_for_extmark = wlv->extra_for_extmark;
wlv->saved_c_extra = wlv->c_extra;
wlv->saved_c_final = wlv->c_final;
+ wlv->need_lbr = true;
wlv->saved_char_attr = wlv->char_attr;
wlv->n_extra = 0;
@@ -2302,9 +2307,19 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool number_onl
wlv.char_attr = hl_combine_attr(term_attrs[wlv.vcol], wlv.char_attr);
}
+ // we don't want linebreak to apply for lines that start with
+ // leading spaces, followed by long letters (since it would add
+ // a break at the beginning of a line and this might be unexpected)
+ //
+ // So only allow to linebreak, once we have found chars not in
+ // 'breakat' in the line.
+ if (wp->w_p_lbr && !wlv.need_lbr && c != NUL
+ && !vim_isbreak((uint8_t)(*ptr))) {
+ wlv.need_lbr = true;
+ }
// Found last space before word: check for line break.
- if (wp->w_p_lbr && c0 == c && vim_isbreak(c)
- && !vim_isbreak((int)(*ptr))) {
+ if (wp->w_p_lbr && c0 == c && wlv.need_lbr
+ && vim_isbreak(c) && !vim_isbreak((uint8_t)(*ptr))) {
int mb_off = utf_head_off(line, ptr - 1);
char *p = ptr - (mb_off + 1);
chartabsize_T cts;