%bw!
endfunc
+" Test that auto-format ('a' flag) preserves spaces typed in the middle of a line
+func Test_fo_a_midline_space()
+ new
+ let lines = [
+ \ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa it but',
+ \ 'Lorem Ipsum is simply dummy text of the printing and typesetting dasddd',
+ \ 'industry.',
+ \ ]
+ call setline(1, lines)
+ set fo=ta tw=70
+
+ " Prevent INPUT_BUFLEN batching so auto_format runs between keystrokes
+ autocmd InsertCharPre * " nothing
+
+ " Position at 't' of 'it' (col 68) and type space then Z
+ call cursor(1, 68)
+ call feedkeys("a Z\<Esc>", 'xt')
+
+ " The space between 'it' and 'Z' must be preserved
+ call assert_match('it Z', getline(1))
+
+ autocmd! InsertCharPre
+ set fo& tw&
+ bw!
+endfunc
+
" Test for formatting lines using gq in visual mode
func Test_visual_gq_format()
new
curwin->w_cursor = pos;
}
+ // Also skip formatting when the user just typed whitespace in the
+ // middle of the line. Reformatting would join all paragraph lines and
+ // re-wrap, consuming the space at the line break point via
+ // OPENLINE_DELSPACES. By deferring, the next non-whitespace character
+ // will be inserted adjacent to the space, keeping it protected from
+ // being consumed at a line break. auto_format() will then reformat
+ // properly on the next keystroke.
+ if (*old != NUL && !trailblank && !wasatend && pos.col > 0
+ && (State & MODE_INSERT))
+ {
+ char_u *line = ml_get_curline();
+ if (WHITECHAR(line[pos.col - 1]))
+ {
+ curwin->w_cursor = pos;
+ return;
+ }
+ }
+
// With the 'c' flag in 'formatoptions' and 't' missing: only format
// comments.
if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP)