Skip to content

Commit 703f9bc

Browse files
zeertzjqvanaigr
authored andcommitted
patch 9.1.0054: 'linebreak' may still apply to leading whitespace
Problem: 'linebreak' may still apply to leading whitespace (VanaIgr) Solution: Compare pointers instead of virtual columns. (zeertzjq) related: neovim/neovim#27180 closes: #13915 Co-authored-by: VanaIgr <vanaigranov@gmail.com> Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 12b9277 commit 703f9bc

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/charset.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,6 @@ win_lbr_chartabsize(
11261126
int n;
11271127
char_u *sbr;
11281128
int no_sbr = FALSE;
1129-
colnr_T vcol_start = 0; // start from where to consider linebreak
11301129
#endif
11311130

11321131
#if defined(FEAT_PROP_POPUP)
@@ -1352,22 +1351,21 @@ win_lbr_chartabsize(
13521351
if (headp != NULL)
13531352
*headp = head;
13541353

1354+
int need_lbr = FALSE;
13551355
/*
13561356
* If 'linebreak' set check at a blank before a non-blank if the line
1357-
* needs a break here
1357+
* needs a break here.
13581358
*/
1359-
if (wp->w_p_lbr && wp->w_p_wrap && wp->w_width != 0)
1359+
if (wp->w_p_lbr && wp->w_p_wrap && wp->w_width != 0
1360+
&& VIM_ISBREAK((int)s[0]) && !VIM_ISBREAK((int)s[1]))
13601361
{
13611362
char_u *t = cts->cts_line;
13621363
while (VIM_ISBREAK((int)t[0]))
13631364
t++;
1364-
vcol_start = t - cts->cts_line;
1365+
// 'linebreak' is only needed when not in leading whitespace.
1366+
need_lbr = s >= t;
13651367
}
1366-
if (wp->w_p_lbr && vcol_start <= vcol
1367-
&& VIM_ISBREAK((int)s[0])
1368-
&& !VIM_ISBREAK((int)s[1])
1369-
&& wp->w_p_wrap
1370-
&& wp->w_width != 0)
1368+
if (need_lbr)
13711369
{
13721370
/*
13731371
* Count all characters from first non-blank after a blank up to next

src/testdir/test_listlbr.vim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,13 @@ endfunc
374374

375375
func Test_linebreak_no_break_after_whitespace_only()
376376
call s:test_windows('setl ts=4 linebreak wrap')
377-
call setline(1, "\tabcdefghijklmnopqrstuvwxyz" ..
377+
call setline(1, "\t abcdefghijklmnopqrstuvwxyz" ..
378378
\ "abcdefghijklmnopqrstuvwxyz")
379379
let lines = s:screen_lines([1, 4], winwidth(0))
380380
let expect = [
381-
\ " abcdefghijklmnop",
382-
\ "qrstuvwxyzabcdefghij",
383-
\ "klmnopqrstuvwxyz ",
381+
\ " abcdefghijklmn",
382+
\ "opqrstuvwxyzabcdefgh",
383+
\ "ijklmnopqrstuvwxyz ",
384384
\ "~ ",
385385
\ ]
386386
call s:compare_lines(expect, lines)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
54,
707709
/**/
708710
53,
709711
/**/

0 commit comments

Comments
 (0)