Skip to content

Commit

Permalink
patch 9.1.0377: Formatting text wrong when 'breakindent' is set
Browse files Browse the repository at this point in the history
Problem:  formatting text wrong when 'breakindent' is set
          (Gary Johnson)
Solution: temporarily disable 'breakindent' option when formatting text,
          so that the breakindent is not wrongly taken into account for
          the line length

fixes: #14630
closes: #14637

Signed-off-by: Christian Brabandt <cb@256bit.org>
  • Loading branch information
chrisbra committed Apr 27, 2024
1 parent 9291706 commit 86ef815
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/testdir/test_textformat.vim
Expand Up @@ -1312,4 +1312,28 @@ func Test_textwdith_overflow()
bw!
endfunc

func Test_breakindent_reformat()
" Make sure textformatting uses the full width
" of the textwidth and does not consider the indent
" from breakindent into account when calculating the
" line length. Should break at tw 78 and not at 70
CheckOption breakindent
new
80vnew
39vnew
setl ai breakindent tw=78
let lorem = [
\ ' Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam luctus',
\ ' lectus sodales, dictum augue vel, molestie augue. Duis sit amet',
\ ' rhoncus justo. Nullam posuere risus semper magna commodo scelerisque.',
\ ' Duis et venenatis sem. In rhoncus augue sed tempor mattis. Mauris id',
\ ' aliquet odio.']
call setline(1, lorem)
norm! gqap
call assert_equal(lorem, getline(1, '$'))
bw!
bw!
bw!
endfunc

" vim: shiftwidth=2 sts=2 expandtab
3 changes: 3 additions & 0 deletions src/textformat.c
Expand Up @@ -59,9 +59,11 @@ internal_format(
int safe_tw = trim_to_int(8 * (vimlong_T)textwidth);
#ifdef FEAT_LINEBREAK
int has_lbr = curwin->w_p_lbr;
int has_bri = curwin->w_p_bri;

// make sure win_lbr_chartabsize() counts correctly
curwin->w_p_lbr = FALSE;
curwin->w_p_bri = FALSE;
#endif

// When 'ai' is off we don't want a space under the cursor to be
Expand Down Expand Up @@ -475,6 +477,7 @@ internal_format(

#ifdef FEAT_LINEBREAK
curwin->w_p_lbr = has_lbr;
curwin->w_p_bri = has_bri;
#endif
if (!format_only && haveto_redraw)
{
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
377,
/**/
376,
/**/
Expand Down

0 comments on commit 86ef815

Please sign in to comment.