summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Brabandt <cb@256bit.org>2023-10-11 21:51:19 +0200
committerChristian Brabandt <cb@256bit.org>2023-10-11 21:53:52 +0200
commitdd75fcfbdff1934c6e531b5a89ebc636318bf4a2 (patch)
tree06026fecb12cc7d18acc8e41f34a5ec2fee2f77e
parent1ea428883f16838aca5763aee156fde3929d9ab6 (diff)
patch 9.0.2017: linebreak applies for leading whitespacev9.0.2017
Problem: linebreak applies for leading whitespace Solution: only apply linebreak, once we have found non-breakat chars in the line closes: #13228 closes: #13243 Signed-off-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--src/charset.c10
-rw-r--r--src/drawline.c24
-rw-r--r--src/testdir/test_listlbr.vim15
-rw-r--r--src/version.c2
4 files changed, 49 insertions, 2 deletions
diff --git a/src/charset.c b/src/charset.c
index dc8fa44833..50a81cccd9 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -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)
@@ -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
diff --git a/src/drawline.c b/src/drawline.c
index 4d63fae34d..309fcd4469 100644
--- a/src/drawline.c
+++ b/src/drawline.c
@@ -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:
@@ -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)
@@ -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
@@ -2905,8 +2916,19 @@ win_line(
}
#endif
#ifdef FEAT_LINEBREAK
+ // 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((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)
diff --git a/src/testdir/test_listlbr.vim b/src/testdir/test_listlbr.vim
index e583e4831a..bcbd886abe 100644
--- a/src/testdir/test_listlbr.vim
+++ b/src/testdir/test_listlbr.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 4031debd86..7db93c42b3 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2017,
+/**/
2016,
/**/
2015,