Skip to content

Commit

Permalink
vim-patch:9.0.2017: linebreak applies for leading whitespace
Browse files Browse the repository at this point in the history
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

vim/vim@dd75fcf

Co-authored-by: Christian Brabandt <cb@256bit.org>
  • Loading branch information
zeertzjq and chrisbra committed Oct 11, 2023
1 parent 7474874 commit 0b15f5e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/nvim/plines.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,17 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp)
*headp = head;
}

colnr_T vcol_start = 0; // start from where to consider linebreak
// If 'linebreak' set check at a blank before a non-blank if the line
// needs a break here
if (wp->w_p_lbr
if (wp->w_p_lbr && wp->w_p_wrap && wp->w_width_inner != 0) {
char *t = cts->cts_line;
while (vim_isbreak((uint8_t)(*t))) {
t++;
}
vcol_start = (colnr_T)(t - cts->cts_line);
}
if (wp->w_p_lbr && vcol_start <= vcol
&& vim_isbreak((uint8_t)s[0])
&& !vim_isbreak((uint8_t)s[1])
&& wp->w_p_wrap
Expand Down
15 changes: 15 additions & 0 deletions test/old/testdir/test_listlbr.vim
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,19 @@ func Test_ctrl_char_on_wrap_column()
call s:close_windows()
endfunc

func Test_linebreak_no_break_after_whitespace_only()
call s:test_windows('setl ts=4 linebreak wrap')
call setline(1, "\tabcdefghijklmnopqrstuvwxyz" ..
\ "abcdefghijklmnopqrstuvwxyz")
let lines = s:screen_lines([1, 4], winwidth(0))
let expect = [
\ " abcdefghijklmnop",
\ "qrstuvwxyzabcdefghij",
\ "klmnopqrstuvwxyz ",
\ "~ ",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc

" vim: shiftwidth=2 sts=2 expandtab

0 comments on commit 0b15f5e

Please sign in to comment.