Skip to content

Commit

Permalink
Linebreak should not apply for leading whitespace
Browse files Browse the repository at this point in the history
gh-issue 13228, linebreak only applies after first non-whitespce
  • Loading branch information
chrisbra committed Oct 9, 2023
1 parent 5484485 commit 0df9ce2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ win_lbr_chartabsize(
int n;
char_u *sbr;
int no_sbr = FALSE;
colnr_T vcol_start = 0; // start from where to consider linebreak
#endif

#if defined(FEAT_PROP_POPUP)
Expand Down Expand Up @@ -1344,7 +1345,14 @@ win_lbr_chartabsize(
* 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 != 0)
{
char_u *t = cts->cts_line;
while (VIM_ISBREAK((int)*t))
t++;
vcol_start = t - cts->cts_line;
}
if (wp->w_p_lbr && vcol_start <= vcol
&& VIM_ISBREAK((int)s[0])
&& !VIM_ISBREAK((int)s[1])
&& wp->w_p_wrap
Expand Down
18 changes: 17 additions & 1 deletion src/drawline.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ typedef struct {
#ifdef FEAT_SIGNS
sign_attrs_T sattr;
#endif
#ifdef FEAT_LINEBREAK
// do consider wrapping in linebreak mode only after encountering
// a non whitespace char
int need_lbr;
#endif
} winlinevars_T;

// draw_state values for items that are drawn in sequence:
Expand Down Expand Up @@ -968,6 +973,9 @@ win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
{
wlv->col = 0;
wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
#ifdef FEAT_LINEBREAK
wlv->need_lbr = FALSE;
#endif

#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
Expand All @@ -994,6 +1002,9 @@ win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
wlv->saved_c_extra = wlv->c_extra;
wlv->saved_c_final = wlv->c_final;
#ifdef FEAT_LINEBREAK
wlv->need_lbr = TRUE;
#endif
#ifdef FEAT_SYN_HL
if (!(wlv->cul_screenline
# ifdef FEAT_DIFF
Expand Down Expand Up @@ -2904,9 +2915,14 @@ win_line(
wlv.char_attr);
}
#endif
#ifdef FEAT_LINEBREAK
if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
!VIM_ISBREAK((int)*ptr))
wlv.need_lbr = TRUE;
#endif
#ifdef FEAT_LINEBREAK
// Found last space before word: check for line break.
if (wp->w_p_lbr && c0 == c
if (wp->w_p_lbr && c0 == c && wlv.need_lbr
&& VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
{
int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
Expand Down
15 changes: 15 additions & 0 deletions src/testdir/test_listlbr.vim
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,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 0df9ce2

Please sign in to comment.