mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.2017: linebreak applies for leading whitespace
Problem: linebreak applies for leading whitespace
Solution: only apply linebreak, once we have found non-breakat chars in
the line
closes: vim/vim#13228
closes: vim/vim#13243
dd75fcfbdf
Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
7474874baa
commit
dac79b165d
@ -127,6 +127,9 @@ typedef struct {
|
|||||||
int filler_lines; ///< nr of filler lines to be drawn
|
int filler_lines; ///< nr of filler lines to be drawn
|
||||||
int filler_todo; ///< nr of filler lines still to do + 1
|
int filler_todo; ///< nr of filler lines still to do + 1
|
||||||
SignTextAttrs sattrs[SIGN_SHOW_MAX]; ///< sign attributes for the sign column
|
SignTextAttrs sattrs[SIGN_SHOW_MAX]; ///< sign attributes for the sign column
|
||||||
|
/// do consider wrapping in linebreak mode only after encountering
|
||||||
|
/// a non whitespace char
|
||||||
|
bool need_lbr;
|
||||||
|
|
||||||
VirtText virt_inline;
|
VirtText virt_inline;
|
||||||
size_t virt_inline_i;
|
size_t virt_inline_i;
|
||||||
@ -1018,6 +1021,7 @@ static void win_line_start(win_T *wp, winlinevars_T *wlv, bool save_extra)
|
|||||||
{
|
{
|
||||||
wlv->col = 0;
|
wlv->col = 0;
|
||||||
wlv->off = 0;
|
wlv->off = 0;
|
||||||
|
wlv->need_lbr = false;
|
||||||
|
|
||||||
if (wp->w_p_rl) {
|
if (wp->w_p_rl) {
|
||||||
// Rightleft window: process the text in the normal direction, but put
|
// Rightleft window: process the text in the normal direction, but put
|
||||||
@ -1038,6 +1042,7 @@ static void win_line_start(win_T *wp, winlinevars_T *wlv, bool save_extra)
|
|||||||
wlv->saved_extra_for_extmark = wlv->extra_for_extmark;
|
wlv->saved_extra_for_extmark = wlv->extra_for_extmark;
|
||||||
wlv->saved_c_extra = wlv->c_extra;
|
wlv->saved_c_extra = wlv->c_extra;
|
||||||
wlv->saved_c_final = wlv->c_final;
|
wlv->saved_c_final = wlv->c_final;
|
||||||
|
wlv->need_lbr = true;
|
||||||
wlv->saved_char_attr = wlv->char_attr;
|
wlv->saved_char_attr = wlv->char_attr;
|
||||||
|
|
||||||
wlv->n_extra = 0;
|
wlv->n_extra = 0;
|
||||||
@ -2302,9 +2307,19 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool number_onl
|
|||||||
wlv.char_attr = hl_combine_attr(term_attrs[wlv.vcol], wlv.char_attr);
|
wlv.char_attr = hl_combine_attr(term_attrs[wlv.vcol], wlv.char_attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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((uint8_t)(*ptr))) {
|
||||||
|
wlv.need_lbr = true;
|
||||||
|
}
|
||||||
// Found last space before word: check for line break.
|
// Found last space before word: check for line break.
|
||||||
if (wp->w_p_lbr && c0 == c && vim_isbreak(c)
|
if (wp->w_p_lbr && c0 == c && wlv.need_lbr
|
||||||
&& !vim_isbreak((int)(*ptr))) {
|
&& vim_isbreak(c) && !vim_isbreak((uint8_t)(*ptr))) {
|
||||||
int mb_off = utf_head_off(line, ptr - 1);
|
int mb_off = utf_head_off(line, ptr - 1);
|
||||||
char *p = ptr - (mb_off + 1);
|
char *p = ptr - (mb_off + 1);
|
||||||
chartabsize_T cts;
|
chartabsize_T cts;
|
||||||
|
@ -340,9 +340,17 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp)
|
|||||||
*headp = head;
|
*headp = head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
colnr_T vcol_start = 0; // start from where to consider linebreak
|
||||||
// If 'linebreak' set check at a blank before a non-blank if the line
|
// If 'linebreak' set check at a blank before a non-blank if the line
|
||||||
// needs a break here
|
// needs a break here
|
||||||
if (wp->w_p_lbr
|
if (wp->w_p_lbr && wp->w_p_wrap && wp->w_width_inner != 0) {
|
||||||
|
char *t = cts->cts_line;
|
||||||
|
while (vim_isbreak((uint8_t)(*t))) {
|
||||||
|
t++;
|
||||||
|
}
|
||||||
|
vcol_start = (colnr_T)(t - cts->cts_line);
|
||||||
|
}
|
||||||
|
if (wp->w_p_lbr && vcol_start <= vcol
|
||||||
&& vim_isbreak((uint8_t)s[0])
|
&& vim_isbreak((uint8_t)s[0])
|
||||||
&& !vim_isbreak((uint8_t)s[1])
|
&& !vim_isbreak((uint8_t)s[1])
|
||||||
&& wp->w_p_wrap
|
&& wp->w_p_wrap
|
||||||
|
@ -373,4 +373,19 @@ func Test_ctrl_char_on_wrap_column()
|
|||||||
call s:close_windows()
|
call s:close_windows()
|
||||||
endfunc
|
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
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Loading…
Reference in New Issue
Block a user